RemoteMediaClient tracksChooser pigeon

This commit is contained in:
gianlucaparadise 2021-12-10 08:14:47 +01:00
parent dcf62d0af6
commit e52b24861c
7 changed files with 74 additions and 1 deletions

View file

@ -403,6 +403,7 @@ public class PlatformBridgeApis {
void play(); void play();
void pause(); void pause();
void stop(); void stop();
void showTracksChooserDialog();
/** The codec used by CastHostApi. */ /** The codec used by CastHostApi. */
static MessageCodec<Object> getCodec() { static MessageCodec<Object> getCodec() {
@ -597,6 +598,25 @@ public class PlatformBridgeApis {
channel.setMessageHandler(null); channel.setMessageHandler(null);
} }
} }
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.showTracksChooserDialog", getCodec());
if (api != null) {
channel.setMessageHandler((message, reply) -> {
Map<String, Object> wrapped = new HashMap<>();
try {
api.showTracksChooserDialog();
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

@ -108,6 +108,7 @@ NSObject<FlutterMessageCodec> *CastHostApiGetCodec(void);
- (void)playWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)playWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)pauseWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)pauseWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error;
- (void)showTracksChooserDialogWithError:(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

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

View file

@ -500,6 +500,29 @@ class CastHostApi {
return; return;
} }
} }
Future<void> showTracksChooserDialog() async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.CastHostApi.showTracksChooserDialog', 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

@ -64,6 +64,11 @@ class RemoteMediaClient {
return await _hostApi.getMediaInfo(); return await _hostApi.getMediaInfo();
} }
/// A Dialog to show the available tracks (Text and Audio) for user to select.
void showTracksChooserDialog() {
_hostApi.showTracksChooserDialog();
}
/// Internal method that shouldn't be visible /// Internal method that shouldn't be visible
@internal @internal
void dispatchPlayerStateUpdate(PlayerState playerState) { void dispatchPlayerStateUpdate(PlayerState playerState) {

View file

@ -36,6 +36,11 @@ class _ExpandedControlsPlayerState extends State<ExpandedControlsPlayer> {
}); });
} }
void _onClosedCaptionClicked() {
final sessionManager = widget.castFramework.castContext.sessionManager;
sessionManager.remoteMediaClient.showTracksChooserDialog();
}
Widget _getIconButton(IconData icon, VoidCallback? onPressed) { Widget _getIconButton(IconData icon, VoidCallback? onPressed) {
return IconButton( return IconButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -101,7 +106,7 @@ class _ExpandedControlsPlayerState extends State<ExpandedControlsPlayer> {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
_getIconButton(Icons.closed_caption, null), _getIconButton(Icons.closed_caption, _onClosedCaptionClicked),
_getIconButton(Icons.skip_previous, null), _getIconButton(Icons.skip_previous, null),
_getPlayPauseButton(playerState), _getPlayPauseButton(playerState),
_getIconButton(Icons.skip_next, null), _getIconButton(Icons.skip_next, null),

View file

@ -236,6 +236,7 @@ abstract class CastHostApi {
void play(); void play();
void pause(); void pause();
void stop(); void stop();
void showTracksChooserDialog();
//endregion //endregion
} }