RemoteMediaClient GetMediaInfo pigeons
This commit is contained in:
parent
9ef284dd4a
commit
d7a8bb5f90
5 changed files with 63 additions and 0 deletions
|
|
@ -357,6 +357,7 @@ public class PlatformBridgeApis {
|
||||||
void sendMessage(CastMessage message);
|
void sendMessage(CastMessage message);
|
||||||
void showCastDialog();
|
void showCastDialog();
|
||||||
void loadMediaLoadRequestData(MediaLoadRequestData request);
|
void loadMediaLoadRequestData(MediaLoadRequestData request);
|
||||||
|
MediaInfo getMediaInfo();
|
||||||
|
|
||||||
/** The codec used by CastHostApi. */
|
/** The codec used by CastHostApi. */
|
||||||
static MessageCodec<Object> getCodec() {
|
static MessageCodec<Object> getCodec() {
|
||||||
|
|
@ -432,6 +433,25 @@ public class PlatformBridgeApis {
|
||||||
channel.setMessageHandler(null);
|
channel.setMessageHandler(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
BasicMessageChannel<Object> channel =
|
||||||
|
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.getMediaInfo", getCodec());
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler((message, reply) -> {
|
||||||
|
Map<String, Object> wrapped = new HashMap<>();
|
||||||
|
try {
|
||||||
|
MediaInfo output = api.getMediaInfo();
|
||||||
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
|
||||||
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
- (void)loadMediaLoadRequestDataRequest:(MediaLoadRequestData *)request error:(FlutterError *_Nullable *_Nonnull)error;
|
- (void)loadMediaLoadRequestDataRequest:(MediaLoadRequestData *)request error:(FlutterError *_Nullable *_Nonnull)error;
|
||||||
|
- (nullable MediaInfo *)getMediaInfoWithError:(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);
|
||||||
|
|
|
||||||
|
|
@ -326,6 +326,24 @@ void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastH
|
||||||
[channel setMessageHandler:nil];
|
[channel setMessageHandler:nil];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
FlutterBasicMessageChannel *channel =
|
||||||
|
[FlutterBasicMessageChannel
|
||||||
|
messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.getMediaInfo"
|
||||||
|
binaryMessenger:binaryMessenger
|
||||||
|
codec:CastHostApiGetCodec()];
|
||||||
|
if (api) {
|
||||||
|
NSCAssert([api respondsToSelector:@selector(getMediaInfoWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(getMediaInfoWithError:)", api);
|
||||||
|
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
|
||||||
|
FlutterError *error;
|
||||||
|
MediaInfo *output = [api getMediaInfoWithError:&error];
|
||||||
|
callback(wrapResult(output, error));
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[channel setMessageHandler:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
@interface CastFlutterApiCodecReader : FlutterStandardReader
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,29 @@ class CastHostApi {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<MediaInfo> getMediaInfo() async {
|
||||||
|
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||||
|
'dev.flutter.pigeon.CastHostApi.getMediaInfo', 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 MediaInfo?)!;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CastFlutterApiCodec extends StandardMessageCodec {
|
class _CastFlutterApiCodec extends StandardMessageCodec {
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,7 @@ abstract class CastHostApi {
|
||||||
void sendMessage(CastMessage message);
|
void sendMessage(CastMessage message);
|
||||||
void showCastDialog();
|
void showCastDialog();
|
||||||
void loadMediaLoadRequestData(MediaLoadRequestData request);
|
void loadMediaLoadRequestData(MediaLoadRequestData request);
|
||||||
|
MediaInfo getMediaInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FlutterApi()
|
@FlutterApi()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue