audio_waveforms
audio_waveforms copied to clipboard
Multiple PlayerController Android issue
Describe the bug I have a chat app where if one waveform exists, it's fine. Adding another widget to the list that's not related to it breaks it. Works fine on iOS. To Reproduce Steps to reproduce
Have multiple widgets that use a playercontroller in the widget tree.
Expected behavior On iOS you should be able to play which ever you want. On android it just break and it also does not throw an error. It will be stuck in prepare player. Smartphone (please complete the following information):
- Device: S21
- OS: Android 14
@Yousef-Alabdulhadi Can you please share reproducible code so that we can find the issue?
This is how im preparing it
late final PlayerController playerController;
@override initState() { super.initState(); playerController = PlayerController(); }
Future
preparing = true;
if (mounted) setState(() {});
try {
await playerController
.preparePlayer(
path: audioPath!,
volume: 1.0,
)
.timeout(Duration(seconds: 6), onTimeout: () {
debugPrint('Timeout');
preparing = false;
prepared = false;
if (mounted) setState(() {});
return;
});
} catch (e) {
debugPrint(e.toString());
debugPrint('Timeout');
preparing = false;
prepared = false;
if (mounted) setState(() {});
return;
}
await playerController.extractWaveformData(
path: audioPath!,
noOfSamples: playerWaveStyle.getSamplesForWidth(width),
);
playDuration = playerController.maxDuration ~/ 1000;
widget.message.duration = playDuration;
await db.messageDao.updateDuration(widget.message.id, playDuration);
playerController.onPlayerStateChanged.listen((state) {
if (mounted) setState(() {});
});
playerController.onCurrentDurationChanged.listen((duration) {
playDuration = duration ~/ 1000;
if (mounted) setState(() {});
});
prepared = true;
preparing = false;
if (mounted) setState(() {});
}
@Yousef-Alabdulhadi The only issue with shared code I see is that you're calling extractWaveformData and preparePlayer(shouldExtractWaveform: true(default)) so waveforms are extracted by default with preparePlayer. In this case, you don't have call extractWaveformData again for this. Other than that I will check how you using it in the widget tree and are you using same controller for all widget?
@Yousef-Alabdulhadi, Have you resolved this issue, or are you still facing it? Please update the thread so we can take further steps on this.
@Yousef-Alabdulhadi, Have you resolved this issue, or are you still facing it? Please update the thread so we can take further steps on this.
No not yet, I went with another package. I'll probably get back to it and try to fix it as well.
Closing this issue as of now as no further updates were provided. Feel free to create a new one.
@ujas-m-simformsolutions I still facing it. You can try the example of package with 12 items.