I have the below code where the function clickSound just plays a simple button click sound audio without any loop and the function loopSound plays music in a loop.However I am unable to play both at the same time i.e. (in case the music is playing and I want to click a button for example).
How can I implement that using the same instance or will I have to create two instances and change my code from being a singleton?
Note: I am using the **audioplayers ** package
import 'package:audioplayers/audioplayers.dart';
import 'package:biblequiz/services/preferences.dart';
class AudioService {
AudioPlayer player = AudioPlayer();
static final AudioService instance = AudioService._();
AudioService._() {
this.player.setVolume(1.0);
}
void clickSound() async {
await player.play(AssetSource('sounds/click.mp3'));
}
void loopSound() async {
player.setReleaseMode(ReleaseMode.loop);
await player.play(AssetSource('sounds/music.wav'));
}
void stopLoop() async {
await player.stop();
}
}