Android Question Optimizing Audio Playback for Long Durations with Minimal Power Consumption in Android Apps

fredo

Well-Known Member
Licensed User
Longtime User
A tip is sought for an optimal solution.

In this use case, the app should play a local sound file that may run for more than 20 minutes.

It must be ensured that playback continues even if the app would otherwise go into standby due to energy settings.

It’s known that this function can be controlled using “PhoneWakeState” with “KeepAlive” in Activity_Resume and “ReleaseKeepAlive" in Activity_Pause.

“PartialLock” and “ReleasePartialLock” are also available.

Does it make a difference to start "KeepAlive" in `Activity_Resume` versus immediately before starting the MediaPlayer?

However, due to limited experience in this area, guidance on the best approach is needed to keep the app’s energy consumption within reasonable limits.

Which approach is most effective for ensuring continuous playback while balancing the app’s energy consumption?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Does it make a difference to start "KeepAlive" in `Activity_Resume` versus immediately before starting the MediaPlayer?
It doesn't really matter. KeepAlive prevents the screen from turning off due to lack of activity.

BTW, might be better to use a foreground service for this. With a service it will continue to play even if the user switches to a different app or turns off the screen.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…