RemoteMediaClient tracksChooser pigeon
This commit is contained in:
parent
dcf62d0af6
commit
e52b24861c
7 changed files with 74 additions and 1 deletions
|
|
@ -403,6 +403,7 @@ public class PlatformBridgeApis {
|
|||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
void showTracksChooserDialog();
|
||||
|
||||
/** The codec used by CastHostApi. */
|
||||
static MessageCodec<Object> getCodec() {
|
||||
|
|
@ -597,6 +598,25 @@ public class PlatformBridgeApis {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ NSObject<FlutterMessageCodec> *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<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
||||
|
|
|
|||
|
|
@ -469,6 +469,24 @@ void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastH
|
|||
[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
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -500,6 +500,29 @@ class CastHostApi {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
return IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
|
|
@ -101,7 +106,7 @@ class _ExpandedControlsPlayerState extends State<ExpandedControlsPlayer> {
|
|||
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),
|
||||
|
|
|
|||
|
|
@ -236,6 +236,7 @@ abstract class CastHostApi {
|
|||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
void showTracksChooserDialog();
|
||||
//endregion
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue