我想播放本地文件的播放列表。在android上,没有问题,我可以在Mediaitem(id)中添加本地文件并且它可以正常播放。但在 iOS 上它不起作用。
我收到这个错误:
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: PlatformException((-1002)
unsupported URL, null, null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
<asynchronous suspension>
#2 AudioService.updateQueue (package:audio_service/audio_service.dart:911:5)
<asynchronous suspension>
Run Code Online (Sandbox Code Playgroud)
我知道这个错误来自 AudioService.updatequeue 以及当我设置 AudioSource 时但我不知道如何解决它。
void startAudioService() async{
List<MediaItem> playlist = [];
playlist.add(MediaItem(mylocalFile, ...));
await AudioService.start(
androidStopForegroundOnPause: true,
backgroundTaskEntrypoint: _audioPlayerTaskEntrypoint,
androidNotificationChannelName: 'AudioPlayer',
androidNotificationColor: 0xFF2196f3,
androidNotificationIcon: 'mipmap/ic_launcher',
androidEnableQueue: true,
);
await AudioService.updateQueue(playlist);
await AudioService.skipToQueueItem(playlist[widget.startIndex].id);
}
Run Code Online (Sandbox Code Playgroud)
我尝试像这样设置audioSource,但仍然收到错误:
AudioSource.uri(Uri.file(item.id));
error : [VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: PlatformException(NoSuchMethodError: The getter 'sequence' was called on null.
Run Code Online (Sandbox Code Playgroud)
onUpadeQueue :
@override
Future<void> onUpdateQueue(List<MediaItem> …Run Code Online (Sandbox Code Playgroud)