Suragch
Suragch

Reputation: 512666

Flutter web: uncaught exception for getTemporaryDirectory (path_provider) when using just_audio

I'm using the new experimental LockCachingAudioSource with just_audio. It seems to work on Android and iOS but when I run my app on the web I get the following uncaught error:

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

Here is my code:

_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);

I found a solution so I am posting it below.

Upvotes: 0

Views: 925

Answers (1)

Suragch
Suragch

Reputation: 512666

Currently just_audio doesn't support LockCachingAudioSource on the web. The solution is to use one of the supported AudioSources when running on on the web:

if (kIsWeb) {
  return AudioSource.uri(Uri.parse(url));
}
return LockCachingAudioSource(Uri.parse(url));

Upvotes: 3

Related Questions