-
Notifications
You must be signed in to change notification settings - Fork 845
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
Big performance issues on Android devices. #1799
Comments
Can you provide code how you are using the audio player that plays music? |
Sure,
And create my audioplayer:
When the main feature/game of my app start, this code is run :
The Sounds class, looks something like this:
|
From what I have understood Also I notice that you don't release previous asset before switching to new and you don't cancel previous listener. |
I am going to try your recommendations, but I am not sure that I understand "you don't cancel previous listener". Do you mean I should cancel and renew the onPlayerComplete every time a new music is played? Why? |
Never mind the comment about listener, I understood it wrong |
We currently work on Exoplayer for Android: #1691 If you want to work on a fix for the current media player, you're more than welcome to provide a Merge Request. |
Im currently running into this issue, on iOS things are fine, but on android, the more I play a sound the more of a hit it has on performance, it makes my game laggy as hell at the end, its like a gradual effect, the more I play the sound the more it freezes the game. |
I have this issue right now, not only on android, it's also on desktop and my PC isn't low-end either, but somehow the audio lags when I play them one after another quickly and sometimes doesn't even play at all when I've played it multiple times, performance gets hit |
Checklist
Current bug behaviour
Hi,
First, a bit of context: In my app, I am using 2 audioplayers instances. One that plays a background music (from which I created a subscription with onPlayerComplete to loop over a few different songs), and one that is used to give the user some instructions based on its interaction with the app (the assets are generally 1–2 seconds long and are rarely called).
Problem: I received a lot of complaints from our android users that the app was "hard freezing" from time to time and at complete random moments. After a few trials, I managed to reproduce the issue, and indeed, I couldn't reproduce it consistently. It doesn't seem that the freezes are linked to any specific code or events (not even the one that triggers the "instructions").
I managed to catch those freeze in the CPU profiler and this is what I got:
First, when everything is working fine :
As we can see, the method AudioPlayer.getCurrentPosition accounts for only a fraction of the total CPU usage.
And this is the result when the app is freezing :
The AudioPlayer.getCurrentPosition suddenly account for half of the CPU usage.
Note that:
I am afraid I cannot provide a minimal reproducible example, especially as I struggle reproducing it myself.
Do you have some intuition as to what could make the AudioPlayer.getCurrentPosition so CPU greedy ?
I saw that the function was called on a crazy rate when an asset is being played, is there a way to maybe reduce it ?
(Although, it is the same on iPhones and there is no problem at all, so I guess that is not the problem … )
Should I try to play the music in an isolate ?
Kind regards,
Expected behaviour
No lags.
Steps to reproduce
flutter run
on the code sampleCode sample
Code sample
Affected platforms
Android
Platform details
The one I have reproduced the problem with:
One Plus 8,
Samsung S23,
From user complaints: many more.
AudioPlayers Version
main 6.0.0
Build mode
release
Audio Files/URLs/Sources
No response
Screenshots
No response
Logs
Full Logs
Flutter doctor:
Related issues / more information
No response
Working on PR
no way
The text was updated successfully, but these errors were encountered: