Skip to content

Commit

Permalink
Enable fast forward and rewind via headphone controls.
Browse files Browse the repository at this point in the history
  • Loading branch information
amugofjava committed Jun 29, 2024
1 parent 06174de commit 09f0dd2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/services/audio/default_audio_player_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1019,17 +1019,31 @@ class _DefaultAudioPlayerHandler extends BaseAudioHandler with SeekHandler {
PlaybackState _transformEvent(PlaybackEvent event) {
log.fine('_transformEvent Sending state ${_player.processingState}');

// To enable skip next and previous for headphones on iOS we need the
// add the skipToNext & skipToPrevious controls; however, on Android
// we don't need to specify them and doing so adds the next and previous
// buttons to the notification shade which we do not want.
final systemActions = Platform.isIOS
? const {
MediaAction.seek,
MediaAction.seekForward,
MediaAction.seekBackward,
MediaAction.skipToNext,
MediaAction.skipToPrevious,
}
: const {
MediaAction.seek,
MediaAction.seekForward,
MediaAction.seekBackward,
};

return PlaybackState(
controls: [
rewindControl,
if (_player.playing) MediaControl.pause else MediaControl.play,
fastforwardControl,
],
systemActions: const {
MediaAction.seek,
MediaAction.seekForward,
MediaAction.seekBackward,
},
systemActions: systemActions,
androidCompactActionIndices: const [0, 1, 2],
processingState: {
ProcessingState.idle: _player.playing ? AudioProcessingState.ready : AudioProcessingState.idle,
Expand Down

0 comments on commit 09f0dd2

Please sign in to comment.