Reputation: 137
i already made voice recorder using flutter_sound
,
the sound only play once, maybe someone have try to auto loop when it's play ?
@override
void initState() {
if (widget.voiceofer != null) {
flutterSound.startPlayer(
'/data/user/0/id.captrue.captrue/app_flutter/${widget.voiceofer}');
}
super.initState();
}
Upvotes: 8
Views: 10309
Reputation: 524
"AudioPlayer" works well for me with this implementation:
//Making sound looping.
final bgAudio = AudioPlayer();
void playBackgroundMusic() {
bgAudio.play(
AssetSource('audio/background.mp3'),
);
bgAudio.onPlayerComplete.listen((event) {
bgAudio.play(
AssetSource('audio/background.mp3'),
);
});
Upvotes: 2
Reputation: 119
using new version of audioplayers 1.1.1 you can use setReleaseMode()
Example:
final player = AudioPlayer();
void playSound() async {
await player.play(AssetSource('sound.mp3'));
}
void loop() {
player.setReleaseMode(ReleaseMode.loop);
}
Upvotes: 9
Reputation: 7686
I recommend to use audioplayers
as library who has a build in feature for looping audio.
Link: audioplayers: ^0.14.0
Implementation:
loop
the with name of your file.Example:
static AudioCache musicCache;
static AudioPlayer instance;
void playLoopedMusic() async {
musicCache = AudioCache(prefix: "audio/");
instance = await musicCache.loop("bgmusic.mp3");
// await instance.setVolume(0.5); you can even set the volume
}
void pauseMusic() {
if (instance != null) {
instance.pause();
}
}
Upvotes: 2