QueueNext/Prev pigeon

This commit is contained in:
gianlucaparadise 2022-02-04 06:55:47 +01:00
parent 969bc2c51b
commit 75303691fb
5 changed files with 126 additions and 0 deletions

View file

@ -643,6 +643,8 @@ public class PlatformBridgeApis {
void showTracksChooserDialog(); void showTracksChooserDialog();
void skipAd(); void skipAd();
void queueAppendItem(MediaQueueItem item); void queueAppendItem(MediaQueueItem item);
void queueNextItem();
void queuePrevItem();
/** The codec used by CastHostApi. */ /** The codec used by CastHostApi. */
static MessageCodec<Object> getCodec() { static MessageCodec<Object> getCodec() {
@ -899,6 +901,44 @@ public class PlatformBridgeApis {
channel.setMessageHandler(null); channel.setMessageHandler(null);
} }
} }
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.queueNextItem", getCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
Map<String, Object> 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<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.queuePrevItem", getCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
Map<String, Object> 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 { private static class CastFlutterApiCodec extends StandardMessageCodec {

View file

@ -159,6 +159,8 @@ NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
- (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)showTracksChooserDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)skipAdWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)skipAdWithError:(FlutterError *_Nullable *_Nonnull)error;
- (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)queuePrevItemWithError:(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);

View file

@ -684,6 +684,42 @@ void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastH
[channel setMessageHandler:nil]; [channel setMessageHandler:nil];
} }
} }
{
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.queueNextItem"
binaryMessenger:binaryMessenger
codec:CastHostApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(queueNextItemWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(queueNextItemWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api queueNextItemWithError:&error];
callback(wrapResult(nil, error));
}];
}
else {
[channel setMessageHandler:nil];
}
}
{
FlutterBasicMessageChannel *channel =
[FlutterBasicMessageChannel
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.queuePrevItem"
binaryMessenger:binaryMessenger
codec:CastHostApiGetCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(queuePrevItemWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(queuePrevItemWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
[api queuePrevItemWithError:&error];
callback(wrapResult(nil, error));
}];
}
else {
[channel setMessageHandler:nil];
}
}
} }
@interface CastFlutterApiCodecReader : FlutterStandardReader @interface CastFlutterApiCodecReader : FlutterStandardReader
@end @end

View file

@ -721,6 +721,52 @@ class CastHostApi {
return; return;
} }
} }
Future<void> queueNextItem() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastHostApi.queueNextItem', 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;
}
}
Future<void> queuePrevItem() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastHostApi.queuePrevItem', 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;
}
}
} }
class _CastFlutterApiCodec extends StandardMessageCodec { class _CastFlutterApiCodec extends StandardMessageCodec {

View file

@ -297,6 +297,8 @@ abstract class CastHostApi {
//region Queue //region Queue
void queueAppendItem(MediaQueueItem item); void queueAppendItem(MediaQueueItem item);
void queueNextItem();
void queuePrevItem();
//endregion //endregion
} }