How to play sound from assets folder? #965
Replies: 4 comments 2 replies
-
You need to use AudioCache to play assets files |
Beta Was this translation helpful? Give feedback.
-
You can Play Sound from Assets Folder by instantiating AudioPlayer and then using this line of code |
Beta Was this translation helpful? Give feedback.
-
The audiocache method is deprecated now. It's no longer supported. We now use AudioPlayer() for this functionality. AudioPlayer detects sound automatically in a /assets folder. Just import =>
Then go to your pubspec.yaml file and add the dependency. Say you are using a TextButton for action, write this on your main.dart file =>
|
Beta Was this translation helpful? Give feedback.
-
None of this works for me. I'm new to Dart and may I am wrong, but documentation seems outdated for this package. Weird, it worked after a clean rebuild. void playNote1() async {
final player = AudioPlayer();
await player.play(AssetSource("note1.wav"));
} |
Beta Was this translation helpful? Give feedback.
-
How to play .mp3 and .wav files from assets folder. I tried with is local but its shows file not found. So How it works? I read all document. I couldn't found any solution. Please any one? I want to play just 2-3 sound which are fixed.
Beta Was this translation helpful? Give feedback.
All reactions