ryanheise / audio_service

Flutter plugin to play audio in the background while the screen is off.
803 stars 480 forks source link

Wifi lock on Android #766

Open ryanheise opened 3 years ago

ryanheise commented 3 years ago

Is your feature request related to a problem? Please describe.

On Android, if the audio being played in the background is being streamed over wifi, the wifi needs to be kept alive for that to work.

Describe the solution you'd like

Provide an option to acquire a wifi lock whenever the wifi is needed and release the lock when not needed.

Describe alternatives you've considered

This could alternatively be provided as a feature of other plugins to be used in conjunction with audio_service. E.g. just_audio or wakelock.

Additional context

(TODO: check past issues to see if this solution will help to resolve existing issues.)

keaganhilliard commented 3 years ago

Is this possible to implement for Cellular data as well? I did have an issue that came up with that. WiFi never seemed to be an issue but mobile data had a problem when the stream was paused and resumed from bluetooth.

ryanheise commented 3 years ago

I couldn't find anything similar to a wifi lock for cellular data, so I'm not sure exactly what is going on here. I'd need to probably see how this is handled in other Android apps.

Doing a Google search, I found the following which explains best practices with network connectivity:

https://google-developer-training.github.io/android-developer-advanced-course-concepts/unit-2-make-your-apps-fast-and-small/lesson-4-performance/4-3-c-best-practices-network-battery-compression/4-3-c-best-practices-network-battery-compression.html

But that seems to indicate that cellular network connectivity is managed automatically and using it after a sleep just introduces more latency, not an error.