From 1e8af8a46e11b8638b3f25e75f5a1037b178e39f Mon Sep 17 00:00:00 2001 From: gianlucaparadise Date: Wed, 2 Feb 2022 06:55:16 +0100 Subject: [PATCH] QueueAppend item pigeon --- .../PlatformBridgeApis.java | 92 ++++++++++++++++++- ios/Classes/PlatformBridgeApis.h | 11 +++ ios/Classes/PlatformBridgeApis.m | 71 +++++++++++++- lib/src/PlatformBridgeApis.dart | 69 +++++++++++++- pigeon/PlatformBridgeApisDefinition.dart | 15 +++ 5 files changed, 249 insertions(+), 9 deletions(-) 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 fb8d809..dfbbb4e 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 @@ -435,6 +435,60 @@ public class PlatformBridgeApis { } } + /** Generated class from Pigeon that represents data sent in messages. */ + public static class MediaQueueItem { + private Long itemId; + public Long getItemId() { return itemId; } + public void setItemId(Long setterArg) { this.itemId = setterArg; } + + private Double playbackDuration; + public Double getPlaybackDuration() { return playbackDuration; } + public void setPlaybackDuration(Double setterArg) { this.playbackDuration = setterArg; } + + private Double startTime; + public Double getStartTime() { return startTime; } + public void setStartTime(Double setterArg) { this.startTime = setterArg; } + + private MediaInfo media; + public MediaInfo getMedia() { return media; } + public void setMedia(MediaInfo setterArg) { this.media = setterArg; } + + private Boolean autoplay; + public Boolean getAutoplay() { return autoplay; } + public void setAutoplay(Boolean setterArg) { this.autoplay = setterArg; } + + private Double preloadTime; + public Double getPreloadTime() { return preloadTime; } + public void setPreloadTime(Double setterArg) { this.preloadTime = setterArg; } + + Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("itemId", itemId); + toMapResult.put("playbackDuration", playbackDuration); + toMapResult.put("startTime", startTime); + toMapResult.put("media", (media == null) ? null : media.toMap()); + toMapResult.put("autoplay", autoplay); + toMapResult.put("preloadTime", preloadTime); + return toMapResult; + } + static MediaQueueItem fromMap(Map map) { + MediaQueueItem fromMapResult = new MediaQueueItem(); + Object itemId = map.get("itemId"); + fromMapResult.itemId = (itemId == null) ? null : ((itemId instanceof Integer) ? (Integer)itemId : (Long)itemId); + Object playbackDuration = map.get("playbackDuration"); + fromMapResult.playbackDuration = (Double)playbackDuration; + Object startTime = map.get("startTime"); + fromMapResult.startTime = (Double)startTime; + Object media = map.get("media"); + fromMapResult.media = MediaInfo.fromMap((Map)media); + Object autoplay = map.get("autoplay"); + fromMapResult.autoplay = (Boolean)autoplay; + Object preloadTime = map.get("preloadTime"); + fromMapResult.preloadTime = (Double)preloadTime; + return fromMapResult; + } + } + /** Generated class from Pigeon that represents data sent in messages. */ public static class CastDevice { private String deviceId; @@ -518,9 +572,12 @@ public class PlatformBridgeApis { return MediaMetadata.fromMap((Map) readValue(buffer)); case (byte)134: - return MediaTrack.fromMap((Map) readValue(buffer)); + return MediaQueueItem.fromMap((Map) readValue(buffer)); case (byte)135: + return MediaTrack.fromMap((Map) readValue(buffer)); + + case (byte)136: return WebImage.fromMap((Map) readValue(buffer)); default: @@ -554,12 +611,16 @@ public class PlatformBridgeApis { stream.write(133); writeValue(stream, ((MediaMetadata) value).toMap()); } else - if (value instanceof MediaTrack) { + if (value instanceof MediaQueueItem) { stream.write(134); + writeValue(stream, ((MediaQueueItem) value).toMap()); + } else + if (value instanceof MediaTrack) { + stream.write(135); writeValue(stream, ((MediaTrack) value).toMap()); } else if (value instanceof WebImage) { - stream.write(135); + stream.write(136); writeValue(stream, ((WebImage) value).toMap()); } else { @@ -581,6 +642,7 @@ public class PlatformBridgeApis { void stop(); void showTracksChooserDialog(); void skipAd(); + void queueAppendItem(MediaQueueItem item); /** The codec used by CastHostApi. */ static MessageCodec getCodec() { @@ -813,6 +875,30 @@ public class PlatformBridgeApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.queueAppendItem", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + MediaQueueItem itemArg = (MediaQueueItem)args.get(0); + if (itemArg == null) { + throw new NullPointerException("itemArg unexpectedly null."); + } + api.queueAppendItem(itemArg); + 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 d6b093d..caaaa93 100644 --- a/ios/Classes/PlatformBridgeApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -59,6 +59,7 @@ typedef NS_ENUM(NSUInteger, PlayerState) { @class MediaStatus; @class AdBreakStatus; @class AdBreakClipInfo; +@class MediaQueueItem; @class CastDevice; @class CastMessage; @@ -122,6 +123,15 @@ typedef NS_ENUM(NSUInteger, PlayerState) { @property(nonatomic, strong, nullable) NSNumber * whenSkippableMs; @end +@interface MediaQueueItem : NSObject +@property(nonatomic, strong, nullable) NSNumber * itemId; +@property(nonatomic, strong, nullable) NSNumber * playbackDuration; +@property(nonatomic, strong, nullable) NSNumber * startTime; +@property(nonatomic, strong, nullable) MediaInfo * media; +@property(nonatomic, strong, nullable) NSNumber * autoplay; +@property(nonatomic, strong, nullable) NSNumber * preloadTime; +@end + @interface CastDevice : NSObject @property(nonatomic, copy, nullable) NSString * deviceId; @property(nonatomic, copy, nullable) NSString * friendlyName; @@ -148,6 +158,7 @@ NSObject *CastHostApiGetCodec(void); - (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)skipAdWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)queueAppendItemItem:(MediaQueueItem *)item 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 ecb84e1..7d3ef53 100644 --- a/ios/Classes/PlatformBridgeApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -54,6 +54,10 @@ static NSDictionary *wrapResult(id result, FlutterError *error) + (AdBreakClipInfo *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @end +@interface MediaQueueItem () ++ (MediaQueueItem *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end @interface CastDevice () + (CastDevice *)fromMap:(NSDictionary *)dict; - (NSDictionary *)toMap; @@ -272,6 +276,40 @@ static NSDictionary *wrapResult(id result, FlutterError *error) } @end +@implementation MediaQueueItem ++ (MediaQueueItem *)fromMap:(NSDictionary *)dict { + MediaQueueItem *result = [[MediaQueueItem alloc] init]; + result.itemId = dict[@"itemId"]; + if ((NSNull *)result.itemId == [NSNull null]) { + result.itemId = nil; + } + result.playbackDuration = dict[@"playbackDuration"]; + if ((NSNull *)result.playbackDuration == [NSNull null]) { + result.playbackDuration = nil; + } + result.startTime = dict[@"startTime"]; + if ((NSNull *)result.startTime == [NSNull null]) { + result.startTime = nil; + } + result.media = [MediaInfo fromMap:dict[@"media"]]; + if ((NSNull *)result.media == [NSNull null]) { + result.media = nil; + } + result.autoplay = dict[@"autoplay"]; + if ((NSNull *)result.autoplay == [NSNull null]) { + result.autoplay = nil; + } + result.preloadTime = dict[@"preloadTime"]; + if ((NSNull *)result.preloadTime == [NSNull null]) { + result.preloadTime = nil; + } + return result; +} +- (NSDictionary *)toMap { + return [NSDictionary dictionaryWithObjectsAndKeys:(self.itemId ? self.itemId : [NSNull null]), @"itemId", (self.playbackDuration ? self.playbackDuration : [NSNull null]), @"playbackDuration", (self.startTime ? self.startTime : [NSNull null]), @"startTime", (self.media ? [self.media toMap] : [NSNull null]), @"media", (self.autoplay ? self.autoplay : [NSNull null]), @"autoplay", (self.preloadTime ? self.preloadTime : [NSNull null]), @"preloadTime", nil]; +} +@end + @implementation CastDevice + (CastDevice *)fromMap:(NSDictionary *)dict { CastDevice *result = [[CastDevice alloc] init]; @@ -337,9 +375,12 @@ static NSDictionary *wrapResult(id result, FlutterError *error) return [MediaMetadata fromMap:[self readValue]]; case 134: - return [MediaTrack fromMap:[self readValue]]; + return [MediaQueueItem fromMap:[self readValue]]; case 135: + return [MediaTrack fromMap:[self readValue]]; + + case 136: return [WebImage fromMap:[self readValue]]; default: @@ -378,14 +419,18 @@ static NSDictionary *wrapResult(id result, FlutterError *error) [self writeByte:133]; [self writeValue:[value toMap]]; } else - if ([value isKindOfClass:[MediaTrack class]]) { + if ([value isKindOfClass:[MediaQueueItem class]]) { [self writeByte:134]; [self writeValue:[value toMap]]; } else - if ([value isKindOfClass:[WebImage class]]) { + if ([value isKindOfClass:[MediaTrack class]]) { [self writeByte:135]; [self writeValue:[value toMap]]; } else + if ([value isKindOfClass:[WebImage class]]) { + [self writeByte:136]; + [self writeValue:[value toMap]]; + } else { [super writeValue:value]; } @@ -619,6 +664,26 @@ void CastHostApiSetup(id binaryMessenger, NSObject pigeonMap = {}; + pigeonMap['itemId'] = itemId; + pigeonMap['playbackDuration'] = playbackDuration; + pigeonMap['startTime'] = startTime; + pigeonMap['media'] = media == null ? null : media!.encode(); + pigeonMap['autoplay'] = autoplay; + pigeonMap['preloadTime'] = preloadTime; + return pigeonMap; + } + + static MediaQueueItem decode(Object message) { + final Map pigeonMap = message as Map; + return MediaQueueItem() + ..itemId = pigeonMap['itemId'] as int? + ..playbackDuration = pigeonMap['playbackDuration'] as double? + ..startTime = pigeonMap['startTime'] as double? + ..media = pigeonMap['media'] != null + ? MediaInfo.decode(pigeonMap['media']!) + : null + ..autoplay = pigeonMap['autoplay'] as bool? + ..preloadTime = pigeonMap['preloadTime'] as double?; + } +} + class CastDevice { String? deviceId; String? friendlyName; @@ -350,14 +383,18 @@ class _CastHostApiCodec extends StandardMessageCodec { buffer.putUint8(133); writeValue(buffer, value.encode()); } else - if (value is MediaTrack) { + if (value is MediaQueueItem) { buffer.putUint8(134); writeValue(buffer, value.encode()); } else - if (value is WebImage) { + if (value is MediaTrack) { buffer.putUint8(135); writeValue(buffer, value.encode()); } else + if (value is WebImage) { + buffer.putUint8(136); + writeValue(buffer, value.encode()); + } else { super.writeValue(buffer, value); } @@ -384,9 +421,12 @@ class _CastHostApiCodec extends StandardMessageCodec { return MediaMetadata.decode(readValue(buffer)!); case 134: - return MediaTrack.decode(readValue(buffer)!); + return MediaQueueItem.decode(readValue(buffer)!); case 135: + return MediaTrack.decode(readValue(buffer)!); + + case 136: return WebImage.decode(readValue(buffer)!); default: @@ -658,6 +698,29 @@ class CastHostApi { return; } } + + Future queueAppendItem(MediaQueueItem arg_item) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.queueAppendItem', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_item]) 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 5f43870..ea69c8a 100644 --- a/pigeon/PlatformBridgeApisDefinition.dart +++ b/pigeon/PlatformBridgeApisDefinition.dart @@ -255,6 +255,17 @@ class AdBreakClipInfo { //#endregion +//#region Queue +class MediaQueueItem { + int? itemId; + double? playbackDuration; + double? startTime; + MediaInfo? media; + bool? autoplay; + double? preloadTime; +} +//#endregion + class CastDevice { String? deviceId; String? friendlyName; @@ -283,6 +294,10 @@ abstract class CastHostApi { void showTracksChooserDialog(); void skipAd(); //endregion + + //region Queue + void queueAppendItem(MediaQueueItem item); + //endregion } /// APIs for Host-to-Flutter comunication