mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-07 21:48:14 -08:00
fix: Media-control pausing of media (#213)
Co-authored-by: PartyDonut <PartyDonut@users.noreply.github.com>
This commit is contained in:
parent
6a34eada67
commit
e07f280124
1 changed files with 21 additions and 4 deletions
|
|
@ -49,7 +49,7 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
|||
bool initMediaControls = false;
|
||||
|
||||
Future<void> init() async {
|
||||
if (!initMediaControls && !kDebugMode) {
|
||||
if (!initMediaControls) {
|
||||
await AudioService.init(
|
||||
builder: () => this,
|
||||
config: const AudioServiceConfig(
|
||||
|
|
@ -153,6 +153,20 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
|||
}));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> pause() async {
|
||||
await _player?.pause();
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
playing: false,
|
||||
controls: [MediaControl.play],
|
||||
));
|
||||
WakelockPlus.disable();
|
||||
final playerState = _player;
|
||||
if (playerState != null) {
|
||||
ref.read(playBackModel)?.updatePlaybackPosition(playerState.lastState.position, false, ref);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> play() async {
|
||||
WakelockPlus.enable();
|
||||
|
|
@ -240,15 +254,18 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
|||
|
||||
Future<void> playOrPause() async {
|
||||
await _player?.playOrPause();
|
||||
final playing = _player?.lastState.playing ?? false;
|
||||
playbackState.add(playbackState.value.copyWith(
|
||||
playing: _player?.lastState.playing ?? false,
|
||||
controls: [MediaControl.play],
|
||||
playing: playing,
|
||||
controls: [playing ? MediaControl.pause : MediaControl.play],
|
||||
));
|
||||
if (playbackState.value.playing) {
|
||||
|
||||
if (playing) {
|
||||
WakelockPlus.enable();
|
||||
} else {
|
||||
WakelockPlus.disable();
|
||||
}
|
||||
|
||||
final playerState = _player;
|
||||
if (playerState != null) {
|
||||
ref
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue