1

i tried to play my audio i downloaded audioplayers dependecies in pubspec.yaml and i added my assets

but the problem is whenever im trying to play the audşo it throws exceptiob because of the assets are in some files so it cant see it and says that the path is empty

so how can i make it see my source BTW im using assets

Numbers(
            jptext: "ICHI",
            text: "ONE",
            image: Image.asset("assets/images/numbers/number_one.png"),
            icon: IconButton(
              onPressed: () {
                final player = AudioPlayer();
                player.play(
                  AssetSource('number_one_sound.mp3'),
                );

enter image description here

u can see here the filees and the asset sources

i tried to do this but didnt work

final player = AudioPlayer();
                player.setSource(
                  AssetSource('assets/sounds/numbers/'),
                );
                player.play("number_one_sound.mp3" as Source);
              },

1 Answers1

0

If you would like to set your source and play it immediately, use the below code:

final player = AudioPlayer();
player.play(
            AssetSource('sounds/numbers/number_one_sound.mp3'),
);

And if you would like to set the source first and then play the sound later, use the following:

final player = AudioPlayer();
player.setSourceAsset('sounds/numbers/number_one_sound.mp3');
.
.
player.play();

If you haven't already, I recommend you use the audioplayers package instead of the audioplayer, as the latter is out of date.

Firas AT
  • 428
  • 3
  • 4