Zionnite
Zionnite

Reputation: 463

Song Added To Queue not Playing (Using just_audio and audio_service)

Am working on an audio player and I want to pass an individual item to the queue,I needed to do was to pass the params to the controller and from there I was able to pass it to the page_manager and then, I was able to add it to the queue, doing it this way it works very well but the issue I have is that, the moment I comment out _loadPlaylist() and hot-reload, the player will continue to show a loading indicator but the Song name is always shown but the music will continue to load

message_player Controller

i called the below method inside the initState()

addMessageToPlayer({
  required String id,
  required String title,
  required String album,
  required String url,
  required String artUri,
}) {
  final pageManager = getIt<PageManager>();
  pageManager.addMessageToPlayer(
    id: id,
    title: title,
    album: album,
    url: url,
    artUri: artUri,
  );
}

page_manager.dart

inside the Init() i commented out the _loadPlaylist() because i don't need it

void init() async {
//    await _loadPlaylist();
    _listenToPlaybackState();
    _listenToCurrentPosition();
    _listenToBufferedPosition();
    _listenToTotalDuration();
    _listenToChangesInSong();
    _listenToChangesInPlaylist();
  }

Here is the function that adds the items from the controller to the queue

addMessageToPlayer(
      {required String id,
      required String title,
      required String album,
      required String url,
      required String artUri}) {
    // print('ID came ${id}');
    // print('TITLE came ${title}');
    // print('ALBUM came ${album}');
    // print('URL came ${url}');
    // print('ARTURL came ${artUri}');

    final mediaItem = MediaItem(
      id: id,
      title: title,
      album: album,
      extras: {
        'url': url,
        'artUri': artUri,
      },
    );
    _audioHandler.addQueueItem(mediaItem);
  }

Note: If _loadPlaylist() is not commented out, it will work very well

Please what am I missing?

Upvotes: 1

Views: 617

Answers (1)

Zionnite
Zionnite

Reputation: 463

I was able to solve the issue, what I did was to go inside the addQueueItem block and add player.setAudioSource(_playlist); to set the audio player to the latest item

Upvotes: 2

Related Questions