Future<void> _playSound() async {
await _audioPlayer.play(AssetSource('audio.mp3'));
}
assets:
- assets/audio.mp3
i get error
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method getTemporaryDirectory on channel plugins.flutter.io/path_provider)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
<asynchronous suspension>
#1 getTemporaryDirectory (package:path_provider/path_provider.dart:55:24)
<asynchronous suspension>
#2 AudioCache.getTempDir (package:audioplayers/src/audio_cache.dart:76:41)
<asynchronous suspension>
#3 AudioCache.fetchToMemory (package:audioplayers/src/audio_cache.dart:91:37)
<asynchronous suspension>
#4 AudioCache.load (package:audioplayers/src/audio_cache.dart:114:31)
<asynchronous suspension>
#5 AudioPlayer.setSourceAsset (package:audioplayers/src/audioplayer.dart:337:17)
<asynchronous suspension>
#6 AudioPlayer.setSource (package:audioplayers/src/audioplayer.dart:284:5)
<asynchronous suspension>
#7 AudioPlayer.play (package:audioplayers/src/audiopl<…>
I’ve already restarted app, i did flutter clean and after flutter pub get
what’s problem?
2
Answers
The error you’re encountering suggests that the Flutter plugin path_provider is missing or not correctly integrated into your project. This is likely causing issues when fetching the temporary directory for your audio asset.
Make sure you’re calling
WidgetsFlutterBinding.ensureInitialized()
before any other plugin initializations.