Audio control on Flutter
Users should be able to control audio whenever it plays automatically. This includes being able to reduce the volume to zero. It's difficult to hear speech output of the screen reader users when other audio is playing at the same time.
In Flutter apps you should always be able to control audio. Two popular options for playing media are video_player
and just_audio
. Both packages have options for controlling audio through play()
and pause()
methods.
final player = AudioPlayer();
final duration = await player.setUrl('https://appt.org/audio.mp3');
IconButton(
icon: Icon(Icons.play_arrow),
iconSize: 64.0,
onPressed: await player.play(),
);
IconButton(
icon: Icon(Icons.pause),
iconSize: 64.0,
onPressed: await player.pause(),
);