Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter audio_service and just_audio not working on ios

Tags:

flutter

dart

I have list of song on song screen. If user click the one item in the list, I call the loadFirstPlaylist() to load the list of songs(all song in album) into queue and then skip the queue and play. It is working on android but I got following error on iOS. GitHub Sources Code [NowPlaying] [MRNowPlaying] Ignoring setPlaybackState because application does not contain entitlement com.apple.mediaremote.set-playback-state for platform

Future<void> loadFirstPlayList(List<MediaItem> playlist, int index) async {
    await emptyPlaylist();
    if (playlist.isNotEmpty) {
      await _audioHandler.addQueueItems(playlist);
      await _audioHandler.skipToQueueItem(index);
      await _audioHandler.play();
   }
}

Audio Handler Method

@override
Future<void> addQueueItems(List<MediaItem> mediaItems) async {
    // manage Just Audio
    final audioSource = mediaItems.map(_createAudioSource);
    _playlist.addAll(audioSource.toList());

    // notify system
    final newQueue = queue.value..addAll(mediaItems);
    queue.add(newQueue);
}

@override
Future<void> skipToQueueItem(int index) async {
    if (index < 0 || index >= queue.value.length) return;
    if (_player.shuffleModeEnabled) {
      index = _player.shuffleIndices![index];
    }
    _player.seek(Duration.zero, index: index);
 }

@override
Future<void> play() => _player.play();
like image 947
Alex Aung Avatar asked Oct 28 '25 05:10

Alex Aung


1 Answers

I do not know if you have figured it out or not already. However, I had the same issue when trying to load an empty playlist. I was following this example, which includes a _loadEmptyPlaylist method. However, when I implemented it this caused the player to fail silently. It now seems to be working by not calling loadAudioSource on an empty audio sequence.

like image 78
colioli Avatar answered Oct 30 '25 21:10

colioli