How to play custom sound in flutter?

I was able to play a simple sound string of this line of code:

SystemSound.play(SystemSoundType.click); 

How can I play tuned sound?

Say a short mp3

+5
source share
1 answer

Thanks for checking out Flutter!

Today, the Flutter SDK (as of May 5, 2017) does not have built-in support for playing and controlling arbitrary sound. However, we have developed our plugin system to support it.

This plugin adds Flutter sound support: https://pub.dartlang.org/packages/audioplayer

From the README plugin:

 Future play() async { final result = await audioPlayer.play(kUrl); if (result == 1) setState(() => playerState = PlayerState.playing); } // add a isLocal parameter to play a local file Future playLocal() async { final result = await audioPlayer.play(kUrl); if (result == 1) setState(() => playerState = PlayerState.playing); } Future pause() async { final result = await audioPlayer.pause(); if (result == 1) setState(() => playerState = PlayerState.paused); } Future stop() async { final result = await audioPlayer.stop(); if (result == 1) { setState(() { playerState = PlayerState.stopped; position = new Duration(); }); } } 
+8
source

All Articles