I want to play audio and I use audioplayers package. I got this error that said can't find my audio file. I know that has something to do with pubspec.yaml file. I read the same questions and topics and none of them worked for me.
I think the problem is with the way I address my audio file in pubspec. I have a lot of images there and they work just fine.
here is my code:
ElevatedButton(
child: Text('Click me'),
onPressed: () {
final player = AudioPlayer();
player.play(AssetSource(
'lib/assets/audio/2.wav'));
my pubspec file:(the last one is my audio file)
assets:
- lib/assets/img/tab_1.png
- lib/assets/img/tab_1s.png
- lib/assets/img/tab_2.png
- lib/assets/img/tab_2s.png
- lib/assets/img/tab_3.png
- lib/assets/img/tab_3s.png
- lib/assets/img/tab_4.png
- lib/assets/img/tab_4s.png
- lib/assets/img/toman1.png
- lib/assets/img/sp1.jpg
- lib/assets/img/sp2.jpg
- lib/assets/img/sp3.jpg
- lib/assets/img/sp4.jpg
- lib/assets/img/sp5.jpg
- lib/assets/img/header_home_quiz.jpg
- lib/assets/img/animal.jpg
- lib/assets/img/gaav.jpg
- lib/assets/img/sad.png
- lib/assets/img/happy.png
- lib/assets/img/cow.jpg
- lib/assets/img/cat.jpg
- lib/assets/img/dog.jpg
- lib/assets/img/duck.jpg
- lib/assets/img/goose.jpg
- lib/assets/img/lion.jpg
- lib/assets/img/wolf.jpg
- lib/assets/img/mouse.jpg
- lib/assets/img/hen.jpg
- lib/assets/img/roster.jpg
- lib/assets/img/tiger.jpg
- lib/assets/img/snake.jpg
- lib/assets/audio/1.mp3
- lib/assets/audio/2.wav
my folder root:
AssetSource
include root assets
folder by default. You can move your audios to the root level assets>audio
. like
Include path on pubspec.yaml
and then play audio with adding assets
path.
player.play(AssetSource('audio/2.wav'));