From e1b195a4356faed120e8ec57942ac4b21414222a Mon Sep 17 00:00:00 2001 From: gianlucaparadise Date: Thu, 17 Feb 2022 06:33:34 +0100 Subject: [PATCH] MediaQueue methods: pigeon --- .../PlatformBridgeApis.java | 45 ++++++++++++++++++ ios/Classes/PlatformBridgeApis.h | 2 + ios/Classes/PlatformBridgeApis.m | 38 +++++++++++++++ lib/src/PlatformBridgeApis.dart | 46 +++++++++++++++++++ pigeon/PlatformBridgeApisDefinition.dart | 7 ++- 5 files changed, 137 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java index 984a01d..e9df1a6 100644 --- a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java +++ b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java @@ -645,6 +645,8 @@ public class PlatformBridgeApis { void queueAppendItem(MediaQueueItem item); void queueNextItem(); void queuePrevItem(); + Long getQueueItemCount(); + MediaQueueItem getQueueItemAtIndex(Long index); /** The codec used by CastHostApi. */ static MessageCodec getCodec() { @@ -939,6 +941,49 @@ public class PlatformBridgeApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.getQueueItemCount", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + Long output = api.getQueueItemCount(); + wrapped.put("result", output); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.getQueueItemAtIndex", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + Number indexArg = (Number)args.get(0); + if (indexArg == null) { + throw new NullPointerException("indexArg unexpectedly null."); + } + MediaQueueItem output = api.getQueueItemAtIndex(indexArg.longValue()); + wrapped.put("result", output); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } } } private static class CastFlutterApiCodec extends StandardMessageCodec { diff --git a/ios/Classes/PlatformBridgeApis.h b/ios/Classes/PlatformBridgeApis.h index 4194941..3c8efdb 100644 --- a/ios/Classes/PlatformBridgeApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -161,6 +161,8 @@ NSObject *CastHostApiGetCodec(void); - (void)queueAppendItemItem:(MediaQueueItem *)item error:(FlutterError *_Nullable *_Nonnull)error; - (void)queueNextItemWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)queuePrevItemWithError:(FlutterError *_Nullable *_Nonnull)error; +- (nullable NSNumber *)getQueueItemCountWithError:(FlutterError *_Nullable *_Nonnull)error; +- (nullable MediaQueueItem *)getQueueItemAtIndexIndex:(NSNumber *)index error:(FlutterError *_Nullable *_Nonnull)error; @end extern void CastHostApiSetup(id binaryMessenger, NSObject *_Nullable api); diff --git a/ios/Classes/PlatformBridgeApis.m b/ios/Classes/PlatformBridgeApis.m index 2dc9a5e..45b250b 100644 --- a/ios/Classes/PlatformBridgeApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -720,6 +720,44 @@ void CastHostApiSetup(id binaryMessenger, NSObject getQueueItemCount() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.getQueueItemCount', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send(null) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else { + return (replyMap['result'] as int?)!; + } + } + + Future getQueueItemAtIndex(int arg_index) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.getQueueItemAtIndex', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_index]) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else { + return (replyMap['result'] as MediaQueueItem?)!; + } + } } class _CastFlutterApiCodec extends StandardMessageCodec { diff --git a/pigeon/PlatformBridgeApisDefinition.dart b/pigeon/PlatformBridgeApisDefinition.dart index ad5ac0e..605b657 100644 --- a/pigeon/PlatformBridgeApisDefinition.dart +++ b/pigeon/PlatformBridgeApisDefinition.dart @@ -295,11 +295,16 @@ abstract class CastHostApi { void skipAd(); //endregion - //region Queue + //region RemoteMediaClient Queue void queueAppendItem(MediaQueueItem item); void queueNextItem(); void queuePrevItem(); //endregion + + //region MediaQueue + int getQueueItemCount(); + MediaQueueItem getQueueItemAtIndex(int index); + //endregion } /// APIs for Host-to-Flutter comunication