Correct backgrounding behavior for both video and audio (does not work) #4162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #4161 for full explanation.
This is a followup to #4160. It causes keep-screen-alive to only occur for videos (and GIFVs), and for audio attachments it uses setWakeMode (with the required permission added to AndroidManifest.xml). This patch does not work. I can confirm we are hitting the setWakeMode branch*, but when the screen goes to sleep the audio also stops. The documentation says that setWakeMode "should be used together with a foreground android.app.Service for use cases where playback occurs and the screen is off (e.g. background audio playback)", and we have a foreground service but there is no specific provision to switch the audio playback from the activity to the foreground service. I do not know what to do from here.
If the foreground service could assume audio playback, would that mean we could allow audio attachments to keep playing even after the user switches to another app? I think that would be pretty neat.
* I added a log.d to the setWakeMode if, and it printed. I looked in the logcat and there were no warnings around the setWakeMode indicating a permission denial or anything. One minute later I see in the log:
ActivityTrigger activityPauseTrigger
I then immediately see a bunch of audio-related messages I can't decipher, such as:
There were more similar messages after this but I didn't catch them all before they cleared. Various objects claiming both that the music is playing and is not playing.