ExpandedControls setMute
This commit is contained in:
parent
d82e78be12
commit
e65382e4a5
2 changed files with 34 additions and 5 deletions
|
|
@ -58,6 +58,11 @@ class SessionManager {
|
||||||
_hostApi.sendMessage(castMessage);
|
_hostApi.sendMessage(castMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Toggles the stream muting.
|
||||||
|
void setMute(bool muted) {
|
||||||
|
_hostApi.setMute(muted);
|
||||||
|
}
|
||||||
|
|
||||||
RemoteMediaClient? _remoteMediaClient;
|
RemoteMediaClient? _remoteMediaClient;
|
||||||
|
|
||||||
/// Returns the RemoteMediaClient for remote media control.
|
/// Returns the RemoteMediaClient for remote media control.
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,41 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_cast_framework/cast.dart';
|
import 'package:flutter_cast_framework/cast.dart';
|
||||||
|
|
||||||
class ExpandedControlsPlayer extends StatelessWidget {
|
class ExpandedControlsPlayer extends StatefulWidget {
|
||||||
final FlutterCastFramework castFramework;
|
final FlutterCastFramework castFramework;
|
||||||
|
|
||||||
ExpandedControlsPlayer({
|
ExpandedControlsPlayer({
|
||||||
required this.castFramework,
|
required this.castFramework,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ExpandedControlsPlayer> createState() => _ExpandedControlsPlayerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ExpandedControlsPlayerState extends State<ExpandedControlsPlayer> {
|
||||||
|
bool isMute = false;
|
||||||
|
|
||||||
void _onPlayClicked() {
|
void _onPlayClicked() {
|
||||||
final sessionManager = castFramework.castContext.sessionManager;
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
sessionManager.remoteMediaClient.play();
|
sessionManager.remoteMediaClient.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onPauseClicked() {
|
void _onPauseClicked() {
|
||||||
final sessionManager = castFramework.castContext.sessionManager;
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
sessionManager.remoteMediaClient.pause();
|
sessionManager.remoteMediaClient.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onVolumeClicked() {
|
||||||
|
final muted = !isMute;
|
||||||
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
|
sessionManager.setMute(muted);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
if (!mounted) return;
|
||||||
|
isMute = muted;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget _getIconButton(IconData icon, VoidCallback? onPressed) {
|
Widget _getIconButton(IconData icon, VoidCallback? onPressed) {
|
||||||
return IconButton(
|
return IconButton(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
|
@ -65,9 +83,15 @@ class ExpandedControlsPlayer extends StatelessWidget {
|
||||||
return _getBigIconButton(icon, callback);
|
return _getBigIconButton(icon, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _getVolumeButton(bool muted) {
|
||||||
|
final IconData icon = muted ? Icons.volume_off : Icons.volume_up;
|
||||||
|
|
||||||
|
return _getIconButton(icon, _onVolumeClicked);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sessionManager = castFramework.castContext.sessionManager;
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 0),
|
padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 0),
|
||||||
child: ValueListenableBuilder(
|
child: ValueListenableBuilder(
|
||||||
|
|
@ -81,7 +105,7 @@ class ExpandedControlsPlayer extends StatelessWidget {
|
||||||
_getIconButton(Icons.skip_previous, null),
|
_getIconButton(Icons.skip_previous, null),
|
||||||
_getPlayPauseButton(playerState),
|
_getPlayPauseButton(playerState),
|
||||||
_getIconButton(Icons.skip_next, null),
|
_getIconButton(Icons.skip_next, null),
|
||||||
_getIconButton(Icons.volume_up, null),
|
_getVolumeButton(this.isMute),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue