Search code examples
androidflutterdartjust-audioaudio-service

audio_service not showing title in the notification


help me guys implement audio_service in my flutter app , i have already working audio service the cotrols the audio i just want to pair it with audio_service . at the begining i'm trying to make things hard code just to see how it works then pair it with my audio service.

here is the code

class MyAudioHandler extends BaseAudioHandler
    with QueueHandler, // mix in default queue callback implementations
        SeekHandler { // mix in default seek callback implementations

  // The most common callbacks:

  void addd(){
    queue.add([const MediaItem(id: "dd", title: "ss",duration: Duration(seconds: 40))]);
    playbackState.add(
      PlaybackState(
        queueIndex: 0,
        playing: true,
        processingState: AudioProcessingState.loading
      )
    );
  }
  @override
  Future<void> play()async {
    playbackState.add(
     playbackState.value.copyWith(
       processingState: AudioProcessingState.ready,
      playing: true,
      controls: [MediaControl.play],
    )
    );
    dev.log("playing");
  }
  @override
  Future<void> pause() async {
    playbackState.add(playbackState.value.copyWith(
      playing: false,
      controls: [MediaControl.pause],
    ));
    dev.log("pause is called");
  }
  @override
  Future<void> stop() async {
    dev.log("stop is caleld");
  }
  @override
  Future<void> seek(Duration position) async {
     dev.log("seek is called");
  }
  @override
  Future<void> skipToQueueItem(int i) async {
       dev.log("seek is called");
  }
}

i tried to hard code a audio in the function addd , in another place i first call addd then play , which seems to be partialy working , since the control buttons are working as expected :

  • when i click pause or play the correct icon is shown but the problem is no title is shown and also i can't see no progress

Solution

  • You need to broadcast the current media item:

    item = MediaItem(id: "dd", title: "ss", duration: Duration(seconds: 40));
    mediaItem.add(item);