skip to Main Content
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?

2

Answers


  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.

    Login or Signup to reply.
  2. 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());
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search