0

I am new to flutter. I am using flutter audio_service to play music in background. I would like to hide control buttons shown in ios lock screen. I followed to this tutorial by Suragch. I commented out the code that show control, but it only disabled the control button but not hide.

Here is the notify function in audio_handler.dart.

  void _notifyAudioHandlerAboutPlaybackEvents() {
_player.playbackEventStream.listen((PlaybackEvent event) {
  final playing = _player.playing;
  playbackState.add(playbackState.value.copyWith(
    controls: [
     // MediaControl.skipToPrevious,
    //  if (playing) MediaControl.pause else MediaControl.play,
     // MediaControl.stop,
     // MediaControl.skipToNext,
    ],
    systemActions: const {
     // MediaAction.seek,
    },
    androidCompactActionIndices: const [0, 1, 3],
    processingState: const {
      ProcessingState.idle: AudioProcessingState.idle,
      ProcessingState.loading: AudioProcessingState.loading,
      ProcessingState.buffering: AudioProcessingState.buffering,
      ProcessingState.ready: AudioProcessingState.ready,
      ProcessingState.completed: AudioProcessingState.completed,
    }[_player.processingState],
    repeatMode: const {
      LoopMode.off: AudioServiceRepeatMode.none,
      LoopMode.one: AudioServiceRepeatMode.one,
      LoopMode.all: AudioServiceRepeatMode.all,
    }[_player.loopMode],
    shuffleMode: (_player.shuffleModeEnabled)
        ? AudioServiceShuffleMode.all
        : AudioServiceShuffleMode.none,
    playing: playing,
    updatePosition: _player.position,
    bufferedPosition: _player.bufferedPosition,
    speed: _player.speed,
    queueIndex: event.currentIndex,
  ));
});

}

This is my screenshot

XiaoHui
  • 53
  • 6

1 Answers1

0

An app probably shouldn't play media in the background without providing users with a way to turn it off, which is what those buttons are for. Since audio_service is designed to show those buttons, if you don't want those buttons, you can try not using audio_service, but still keep this in your Info.plist file:

  <key>UIBackgroundModes</key>
  <array>
    <string>audio</string>
  </array>
Ryan Heise
  • 2,273
  • 5
  • 14
  • I really like audio_services clean interface design. However, id like to show only some of the MediaControls (Play/ Pause/ App Icon). Do you plan to implement hiding a subset of the controls like the forwarding/ backwarding buttons and the progress bar? – emrich Nov 17 '22 at 10:19