mirror of
https://github.com/gabehf/Fladder.git
synced 2026-03-13 09:20:31 -07: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;
|
bool initMediaControls = false;
|
||||||
|
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
if (!initMediaControls && !kDebugMode) {
|
if (!initMediaControls) {
|
||||||
await AudioService.init(
|
await AudioService.init(
|
||||||
builder: () => this,
|
builder: () => this,
|
||||||
config: const AudioServiceConfig(
|
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
|
@override
|
||||||
Future<void> play() async {
|
Future<void> play() async {
|
||||||
WakelockPlus.enable();
|
WakelockPlus.enable();
|
||||||
|
|
@ -240,15 +254,18 @@ class MediaControlsWrapper extends BaseAudioHandler {
|
||||||
|
|
||||||
Future<void> playOrPause() async {
|
Future<void> playOrPause() async {
|
||||||
await _player?.playOrPause();
|
await _player?.playOrPause();
|
||||||
|
final playing = _player?.lastState.playing ?? false;
|
||||||
playbackState.add(playbackState.value.copyWith(
|
playbackState.add(playbackState.value.copyWith(
|
||||||
playing: _player?.lastState.playing ?? false,
|
playing: playing,
|
||||||
controls: [MediaControl.play],
|
controls: [playing ? MediaControl.pause : MediaControl.play],
|
||||||
));
|
));
|
||||||
if (playbackState.value.playing) {
|
|
||||||
|
if (playing) {
|
||||||
WakelockPlus.enable();
|
WakelockPlus.enable();
|
||||||
} else {
|
} else {
|
||||||
WakelockPlus.disable();
|
WakelockPlus.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
final playerState = _player;
|
final playerState = _player;
|
||||||
if (playerState != null) {
|
if (playerState != null) {
|
||||||
ref
|
ref
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue