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 1e6299f..13f4258 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 @@ -403,6 +403,7 @@ public class PlatformBridgeApis { void play(); void pause(); void stop(); + void showTracksChooserDialog(); /** The codec used by CastHostApi. */ static MessageCodec getCodec() { @@ -597,6 +598,25 @@ public class PlatformBridgeApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.showTracksChooserDialog", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map 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 { diff --git a/ios/Classes/PlatformBridgeApis.h b/ios/Classes/PlatformBridgeApis.h index 8a9caa6..c9eb2f3 100644 --- a/ios/Classes/PlatformBridgeApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -108,6 +108,7 @@ NSObject *CastHostApiGetCodec(void); - (void)playWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)pauseWithError:(FlutterError *_Nullable *_Nonnull)error; - (void)stopWithError:(FlutterError *_Nullable *_Nonnull)error; +- (void)showTracksChooserDialogWithError:(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 804f16f..391138e 100644 --- a/ios/Classes/PlatformBridgeApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -469,6 +469,24 @@ void CastHostApiSetup(id binaryMessenger, NSObject showTracksChooserDialog() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastHostApi.showTracksChooserDialog', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send(null) 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/lib/src/cast/RemoteMediaClient.dart b/lib/src/cast/RemoteMediaClient.dart index b672f07..fd2cd47 100644 --- a/lib/src/cast/RemoteMediaClient.dart +++ b/lib/src/cast/RemoteMediaClient.dart @@ -64,6 +64,11 @@ class RemoteMediaClient { 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 void dispatchPlayerStateUpdate(PlayerState playerState) { diff --git a/lib/src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart b/lib/src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart index 0bdbc8d..fa1d629 100644 --- a/lib/src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart +++ b/lib/src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart @@ -36,6 +36,11 @@ class _ExpandedControlsPlayerState extends State { }); } + void _onClosedCaptionClicked() { + final sessionManager = widget.castFramework.castContext.sessionManager; + sessionManager.remoteMediaClient.showTracksChooserDialog(); + } + Widget _getIconButton(IconData icon, VoidCallback? onPressed) { return IconButton( padding: EdgeInsets.zero, @@ -101,7 +106,7 @@ class _ExpandedControlsPlayerState extends State { return Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - _getIconButton(Icons.closed_caption, null), + _getIconButton(Icons.closed_caption, _onClosedCaptionClicked), _getIconButton(Icons.skip_previous, null), _getPlayPauseButton(playerState), _getIconButton(Icons.skip_next, null), diff --git a/pigeon/PlatformBridgeApisDefinition.dart b/pigeon/PlatformBridgeApisDefinition.dart index 30143f4..b4e43be 100644 --- a/pigeon/PlatformBridgeApisDefinition.dart +++ b/pigeon/PlatformBridgeApisDefinition.dart @@ -236,6 +236,7 @@ abstract class CastHostApi { void play(); void pause(); void stop(); + void showTracksChooserDialog(); //endregion }