From 75303691fb1cf79b6d6e3095a7f146c1da859b68 Mon Sep 17 00:00:00 2001 From: gianlucaparadise Date: Fri, 4 Feb 2022 06:55:47 +0100 Subject: [PATCH] QueueNext/Prev pigeon --- .../PlatformBridgeApis.java | 40 ++++++++++++++++ ios/Classes/PlatformBridgeApis.h | 2 + ios/Classes/PlatformBridgeApis.m | 36 +++++++++++++++ lib/src/PlatformBridgeApis.dart | 46 +++++++++++++++++++ pigeon/PlatformBridgeApisDefinition.dart | 2 + 5 files changed, 126 insertions(+) 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 dfbbb4e..965eec9 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 @@ -643,6 +643,8 @@ public class PlatformBridgeApis { void showTracksChooserDialog(); void skipAd(); void queueAppendItem(MediaQueueItem item); + void queueNextItem(); + void queuePrevItem(); /** The codec used by CastHostApi. */ static MessageCodec getCodec() { @@ -899,6 +901,44 @@ public class PlatformBridgeApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.queueNextItem", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + api.queueNextItem(); + wrapped.put("result", null); + } + 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.queuePrevItem", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + api.queuePrevItem(); + wrapped.put("result", null); + } + 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 caaaa93..d094e0a 100644 --- a/ios/Classes/PlatformBridgeApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -159,6 +159,8 @@ NSObject *CastHostApiGetCodec(void); - (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)skipAdWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)queueAppendItemItem:(MediaQueueItem *)item error:(FlutterError *_Nullable *_Nonnull)error; +- (void)queueNextItemWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)queuePrevItemWithError:(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 7d3ef53..f89734a 100644 --- a/ios/Classes/PlatformBridgeApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -684,6 +684,42 @@ void CastHostApiSetup(id binaryMessenger, NSObject queueNextItem() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.queueNextItem', 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; + } + } + + Future queuePrevItem() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.queuePrevItem', 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; + } + } } class _CastFlutterApiCodec extends StandardMessageCodec { diff --git a/pigeon/PlatformBridgeApisDefinition.dart b/pigeon/PlatformBridgeApisDefinition.dart index ea69c8a..21322b6 100644 --- a/pigeon/PlatformBridgeApisDefinition.dart +++ b/pigeon/PlatformBridgeApisDefinition.dart @@ -297,6 +297,8 @@ abstract class CastHostApi { //region Queue void queueAppendItem(MediaQueueItem item); + void queueNextItem(); + void queuePrevItem(); //endregion }