Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple PlayerController Android issue #347

Open
Yousef-Alabdulhadi opened this issue Oct 18, 2024 · 3 comments
Open

Multiple PlayerController Android issue #347

Yousef-Alabdulhadi opened this issue Oct 18, 2024 · 3 comments
Labels
more-info-required Indicates that the issue requires more description/information

Comments

@Yousef-Alabdulhadi
Copy link

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
@ujas-m-simformsolutions
Copy link
Collaborator

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

@ujas-m-simformsolutions ujas-m-simformsolutions added the more-info-required Indicates that the issue requires more description/information label Oct 18, 2024
@Yousef-Alabdulhadi
Copy link
Author

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(() {});

}

@ujas-m-simformsolutions
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-info-required Indicates that the issue requires more description/information
Projects
None yet
Development

No branches or pull requests

2 participants