我正在使用带有just_audio的新实验LockCachingAudioSource
。它似乎适用于Android和iOS,但当我在网上运行应用程序时,我会收到以下未捕获的错误:
Error: MissingPluginException(No implementation found for method getTemporaryDirectory on channel plugins.flutter.io/path_provider)
at Object.throw_ [as throw] (http://localhost:49168/dart_sdk.js:5041:11)
at platform_channel.MethodChannel.new._invokeMethod (http://localhost:49168/packages/flutter/src/services/system_channels.dart.lib.js:943:21)
at _invokeMethod.next (<anonymous>)
at http://localhost:49168/dart_sdk.js:37403:33
at _RootZone.runUnary (http://localhost:49168/dart_sdk.js:37274:59)
at _FutureListener.thenAwait.handleValue (http://localhost:49168/dart_sdk.js:32530:29)
at handleValueCallback (http://localhost:49168/dart_sdk.js:33057:49)
at Function._propagateToListeners (http://localhost:49168/dart_sdk.js:33095:17)
at _Future.new.[_completeWithValue] (http://localhost:49168/dart_sdk.js:32943:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:49168/dart_sdk.js:32964:35)
at Object._microtaskLoop (http://localhost:49168/dart_sdk.js:37526:13)
at _startMicrotaskLoop (http://localhost:49168/dart_sdk.js:37532:13)
at http://localhost:49168/dart_sdk.js:33303:9
这是我的代码:
_playlist = ConcatenatingAudioSource(
children: mediaItemList
.where((item) => item.extras?['url'] is String)
.map((item) {
final String url = item.extras?['url'];
return LockCachingAudioSource(Uri.parse(url));
}).toList(),
);
await _player.setAudioSource(_playlist);
我找到了一个解决方案,所以我将其发布在下面。
当前just_audio在web上不支持LockCachingAudioSource
。解决方案是在网络上运行时使用支持的AudioSources之一:
if (kIsWeb) {
return AudioSource.uri(Uri.parse(url));
}
return LockCachingAudioSource(Uri.parse(url));