Skip to content

Commit 128d3e3

Browse files
committed
Enhance playback handling during track skipping and fading on double tap BT headsets. Previously, jump to next track and pause, now, next track and play.
1 parent 524a0fc commit 128d3e3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

lib/services/music_player_background_task.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler with SeekHandler, Queue
774774
bool doSkip = true;
775775

776776
try {
777+
final shouldResumePlayback = _player.playing || fadeState.value.fadeDirection != FadeDirection.none;
778+
779+
// Some headsets emit pause before skip on double-tap. If a fade-out pause
780+
// is in progress, reverse it so the next/previous command keeps playback running.
781+
if (fadeState.value.fadeDirection == FadeDirection.fadeOut) {
782+
await fadeInAndPlay();
783+
}
784+
777785
if (_queueCallbackPreviousTrack != null) {
778786
doSkip = await _queueCallbackPreviousTrack!();
779787
} else {
@@ -795,6 +803,10 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler with SeekHandler, Queue
795803
await _player.seek(Duration.zero);
796804
}
797805
}
806+
807+
if (shouldResumePlayback && !_player.playing) {
808+
await play(disableFade: true);
809+
}
798810
} catch (e) {
799811
_audioServiceBackgroundTaskLogger.severe(e);
800812
return Future.error(e);
@@ -804,12 +816,25 @@ class MusicPlayerBackgroundTask extends BaseAudioHandler with SeekHandler, Queue
804816
@override
805817
Future<void> skipToNext() async {
806818
try {
819+
final shouldResumePlayback = _player.playing || fadeState.value.fadeDirection != FadeDirection.none;
820+
821+
// Some headsets emit pause before skip on double-tap. If a fade-out pause
822+
// is in progress, reverse it so the next/previous command keeps playback running.
823+
if (fadeState.value.fadeDirection == FadeDirection.fadeOut) {
824+
await fadeInAndPlay();
825+
}
826+
807827
if (_player.loopMode == LoopMode.one || !_player.hasNext) {
808828
// if the user manually skips to the next track, they probably want to actually skip to the next track
809829
await skipByOffset(1); //!!! don't use _player.nextIndex here, because that adjusts based on loop mode
810830
} else {
811831
await _player.seekToNext();
812832
}
833+
834+
if (shouldResumePlayback && !_player.playing) {
835+
await play(disableFade: true);
836+
}
837+
813838
_audioServiceBackgroundTaskLogger.finer("_player.nextIndex: ${_player.nextIndex}");
814839
} catch (e) {
815840
_audioServiceBackgroundTaskLogger.severe(e);

0 commit comments

Comments
 (0)