audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

Multiple PlayerController Android issue

Open Yousef-Alabdulhadi opened this issue 1 year ago • 3 comments

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 avatar Oct 18 '24 12:10 Yousef-Alabdulhadi

@Yousef-Alabdulhadi Can you please share reproducible code so that we can find the issue?

ujas-m-simformsolutions avatar Oct 18 '24 13:10 ujas-m-simformsolutions

This is how im preparing it

late final PlayerController playerController;

@override initState() { super.initState(); playerController = PlayerController(); }

Future preparePlayer() async { if (audioPath == null) return; debugPrint('Preparing player');

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 avatar Oct 18 '24 16:10 Yousef-Alabdulhadi

@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?

ujas-m-simformsolutions avatar Oct 21 '24 05:10 ujas-m-simformsolutions

@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.

jay-simformsolutions avatar Jan 06 '25 11:01 jay-simformsolutions

@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.

Yousef-Alabdulhadi avatar Jan 08 '25 08:01 Yousef-Alabdulhadi

Closing this issue as of now as no further updates were provided. Feel free to create a new one.

ujas-m-simformsolutions avatar Mar 18 '25 15:03 ujas-m-simformsolutions

@ujas-m-simformsolutions I still facing it. You can try the example of package with 12 items.

Image

datnq97 avatar Sep 29 '25 14:09 datnq97