rodydavis / flutter_midi

Midi Playback in Flutter
https://rodydavis.github.io/flutter_midi/
MIT License
62 stars 56 forks source link

How to properly close and release resource? #13

Open amuhaimin02 opened 4 years ago

amuhaimin02 commented 4 years ago

Hello, good day!

I have been developing a little app (for Android) which uses flutter_midi. Basically the app will allow the user to input notes and play them back,similar to an audio sequencer.

Then one night after developing and testing, I left the app minimized from background (Pressing the home button). The next day, the phone battery level dropped hard and the phone overheats a little. Ultimately I found that the problem is caused by my app.

Upon further research, and by checking the battery graph, I found that my phone is awake at all times. I used Wakelock Detector app to confirm what caused the phone to be in that state, and found that my app is responsible for that. The app has been in CPU Wakelock overnight, consuming and battery.

Then I found that the app process that caused that is called "AudioMix", I suspect that the app is not closed properly due to the audio playback. Even the audio have been stopped playing, the process still keeps running until I eventually closed my app either by force stopping or swiping up from recent apps.

I tried to find a way to make the app to release all possible resource programmatically. However I cannot find that in the flutter_midi documentation. Can only find play_midi_note and stop_midi_note function. Even the stop function cannot completely stop the playback from running

Is there a way to completely close flutter_midi to free up the resource?

TIA

rodydavis commented 4 years ago

If this is android i wouldnt be surprised if that was the case. Im using the built in audio engine.

The plugin is currently being refactored to do more in dart and not relay on these built in synths and we can control disposing better. Stay tuned, should have new info soon