I have made a timer in my flutter app, and I want to implement a countdown sound on timer end.
I have tried to use packages audioplayers and just_audio, but both of those packages resulted in sound being played at lower volume and quality compared to original asset.
Here is a code of implementation using just_audio package.
const boopSound = 'assets/boop.mp3';
const beepSound = 'assets/beep.mp3';
final player1 = AudioPlayer(handleAudioSessionActivation: false);
final player2 = AudioPlayer(handleAudioSessionActivation: false);
@override
void initState() {
_init();
super.initState();
}
Future<void> _init() async {
try {
await player1.setAudioSource(AudioSource.asset(boopSound));
} on PlayerException catch (e) {
print("Error loading audio source: $e");
}
try {
await player2.setAudioSource(AudioSource.asset(beepSound));
} on PlayerException catch (e) {
print("Error loading audio source: $e");
}
}
if(timeLeft == 3 || timeLeft == 2 || timeLeft == 1){
player1.seek(Duration.zero);
player1.play();
}
if(timeLeft == 0){
player2.seek(Duration.zero);
player2.play();
}
I am suspecting that android studio is compressing my asset files while building apk, but I have not found anything online about that.
I have also searched about low sound volume using just_audio and audioplayers packages, but it seems like nobody is having that problems.
Both packages have volume of the sound played set to max by default, but I have also tried setting max volume manually with player.volume(1) function, with no result.
Thank you in advance for helping.
Milos Delic m is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.