Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

issues playing audioplayer in a widget on several page widgets #8

Open
johanhenselmans opened this issue Oct 9, 2017 · 1 comment

Comments

@johanhenselmans
Copy link

I am having issues playing audioplayer in a widget: I have all the initialization code in the initState of the widhet it seems that the audioplayer is initialized everytime the widget is opened in another widget, and remains initialized, which is OK on one hand, because it continues to play when I move from one page to another, but not OK because it is creating more and more audioplayers. I noticed it because I am using a subscription stream to send a message that the audio is playing, and more and more of these messages came through.

Am I doing something wrong? Should I do the initialization in a different way? Or is it just that the objects linger around and wait to be discarded in some kind of garbage collection?

@volgin
Copy link

volgin commented Apr 8, 2018

You can initialize your player separately from your widget or in a static field. In fact, I recommend moving all logic to play/pause, etc. out of the widget state into a separate class (e.g. audio controller) - you only need one for the entire app. The widget in the UI should simply display the current state of playing by subscribing to notifications from the audio controller in it initState().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants