MediaQueue methods: pigeon
This commit is contained in:
parent
f41c18e8c3
commit
e1b195a435
5 changed files with 137 additions and 1 deletions
|
|
@ -645,6 +645,8 @@ public class PlatformBridgeApis {
|
||||||
void queueAppendItem(MediaQueueItem item);
|
void queueAppendItem(MediaQueueItem item);
|
||||||
void queueNextItem();
|
void queueNextItem();
|
||||||
void queuePrevItem();
|
void queuePrevItem();
|
||||||
|
Long getQueueItemCount();
|
||||||
|
MediaQueueItem getQueueItemAtIndex(Long index);
|
||||||
|
|
||||||
/** The codec used by CastHostApi. */
|
/** The codec used by CastHostApi. */
|
||||||
static MessageCodec<Object> getCodec() {
|
static MessageCodec<Object> getCodec() {
|
||||||
|
|
@ -939,6 +941,49 @@ public class PlatformBridgeApis {
|
||||||
channel.setMessageHandler(null);
|
channel.setMessageHandler(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
BasicMessageChannel<Object> channel =
|
||||||
|
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.getQueueItemCount", getCodec());
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler((message, reply) -> {
|
||||||
|
Map<String, Object> 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<Object> channel =
|
||||||
|
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.getQueueItemAtIndex", getCodec());
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler((message, reply) -> {
|
||||||
|
Map<String, Object> wrapped = new HashMap<>();
|
||||||
|
try {
|
||||||
|
ArrayList<Object> args = (ArrayList<Object>)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 {
|
private static class CastFlutterApiCodec extends StandardMessageCodec {
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,8 @@ NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
|
||||||
- (void)queueAppendItemItem:(MediaQueueItem *)item error:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)queueAppendItemItem:(MediaQueueItem *)item error:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)queueNextItemWithError:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)queueNextItemWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)queuePrevItemWithError:(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
|
@end
|
||||||
|
|
||||||
extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
||||||
|
|
|
||||||
|
|
@ -720,6 +720,44 @@ void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastH
|
||||||
[channel setMessageHandler:nil];
|
[channel setMessageHandler:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
FlutterBasicMessageChannel *channel =
|
||||||
|
[FlutterBasicMessageChannel
|
||||||
|
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.getQueueItemCount"
|
||||||
|
binaryMessenger:binaryMessenger
|
||||||
|
codec:CastHostApiGetCodec()];
|
||||||
|
if (api) {
|
||||||
|
NSCAssert([api respondsToSelector:@selector(getQueueItemCountWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(getQueueItemCountWithError:)", api);
|
||||||
|
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||||
|
FlutterError *error;
|
||||||
|
NSNumber *output = [api getQueueItemCountWithError:&error];
|
||||||
|
callback(wrapResult(output, error));
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[channel setMessageHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
FlutterBasicMessageChannel *channel =
|
||||||
|
[FlutterBasicMessageChannel
|
||||||
|
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.getQueueItemAtIndex"
|
||||||
|
binaryMessenger:binaryMessenger
|
||||||
|
codec:CastHostApiGetCodec()];
|
||||||
|
if (api) {
|
||||||
|
NSCAssert([api respondsToSelector:@selector(getQueueItemAtIndexIndex:error:)], @"CastHostApi api (%@) doesn't respond to @selector(getQueueItemAtIndexIndex:error:)", api);
|
||||||
|
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||||
|
NSArray *args = message;
|
||||||
|
NSNumber *arg_index = args[0];
|
||||||
|
FlutterError *error;
|
||||||
|
MediaQueueItem *output = [api getQueueItemAtIndexIndex:arg_index error:&error];
|
||||||
|
callback(wrapResult(output, error));
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[channel setMessageHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -767,6 +767,52 @@ class CastHostApi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> getQueueItemCount() async {
|
||||||
|
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||||
|
'dev.flutter.pigeon.CastHostApi.getQueueItemCount', codec, binaryMessenger: _binaryMessenger);
|
||||||
|
final Map<Object?, Object?>? replyMap =
|
||||||
|
await channel.send(null) as Map<Object?, Object?>?;
|
||||||
|
if (replyMap == null) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: 'channel-error',
|
||||||
|
message: 'Unable to establish connection on channel.',
|
||||||
|
details: null,
|
||||||
|
);
|
||||||
|
} else if (replyMap['error'] != null) {
|
||||||
|
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
|
||||||
|
throw PlatformException(
|
||||||
|
code: (error['code'] as String?)!,
|
||||||
|
message: error['message'] as String?,
|
||||||
|
details: error['details'],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (replyMap['result'] as int?)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<MediaQueueItem> getQueueItemAtIndex(int arg_index) async {
|
||||||
|
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||||
|
'dev.flutter.pigeon.CastHostApi.getQueueItemAtIndex', codec, binaryMessenger: _binaryMessenger);
|
||||||
|
final Map<Object?, Object?>? replyMap =
|
||||||
|
await channel.send(<Object>[arg_index]) as Map<Object?, Object?>?;
|
||||||
|
if (replyMap == null) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: 'channel-error',
|
||||||
|
message: 'Unable to establish connection on channel.',
|
||||||
|
details: null,
|
||||||
|
);
|
||||||
|
} else if (replyMap['error'] != null) {
|
||||||
|
final Map<Object?, Object?> error = (replyMap['error'] as Map<Object?, Object?>?)!;
|
||||||
|
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 {
|
class _CastFlutterApiCodec extends StandardMessageCodec {
|
||||||
|
|
|
||||||
|
|
@ -295,11 +295,16 @@ abstract class CastHostApi {
|
||||||
void skipAd();
|
void skipAd();
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Queue
|
//region RemoteMediaClient Queue
|
||||||
void queueAppendItem(MediaQueueItem item);
|
void queueAppendItem(MediaQueueItem item);
|
||||||
void queueNextItem();
|
void queueNextItem();
|
||||||
void queuePrevItem();
|
void queuePrevItem();
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region MediaQueue
|
||||||
|
int getQueueItemCount();
|
||||||
|
MediaQueueItem getQueueItemAtIndex(int index);
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
/// APIs for Host-to-Flutter comunication
|
/// APIs for Host-to-Flutter comunication
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue