Tom McCaffrey
Tom McCaffrey

Reputation: 121

Specifying background audio controls in Flutter audio_service

Does anyone know how to specify which audio controls can be displayed on the iOS lock screen when using Flutter audio_service? It is documented for Android, but does not seem to be documented for iOS.

I need the lock screen for my app to have the following controls: Play/Pause, skip back, skip next, seek slider, and volume. I have also seen controls for seek backward 10 seconds and seek forward 10 seconds, so it would be useful to know how to select and use them as well.

The official documentation for audio_service includes documentation for the MediaControl class, which evidently only works for Android. There seems to be no similar documentation for iOS. Does anyone know how to specify the media controls on iOS? Thanks!

iOS audio controls with seek buttons

iOS audio controls with skip buttons

Upvotes: 2

Views: 711

Answers (1)

Matt H
Matt H

Reputation: 6532

Set the appropriate PlaybackState properties. Here's what mine looks like for a continuous audio stream:

PlaybackState _transformEvent(PlaybackEvent event) {
    return PlaybackState(
      controls: [
        if (_player.playing) MediaControl.pause else MediaControl.play,
      ],
      androidCompactActionIndices: [MediaAction.play.index, MediaAction.pause.index],
      processingState: const {
        ProcessingState.idle: AudioProcessingState.idle,
        ProcessingState.loading: AudioProcessingState.loading,
        ProcessingState.buffering: AudioProcessingState.buffering,
        ProcessingState.ready: AudioProcessingState.ready,
        ProcessingState.completed: AudioProcessingState.completed,
      }[_player.processingState]!,
      playing: _player.playing,
    );
}

Upvotes: 0

Related Questions