Future<void> _playSound() async {
await _audioPlayer.play(AssetSource('audio.mp3'));
}
assets:
- assets/audio.mp3
enter image description here
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?
Genexys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
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.
why_YaGa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
Make sure you’re calling WidgetsFlutterBinding.ensureInitialized()
before any other plugin initializations.
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart'; // is this imported correctly?
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}