Open paulrinaldi opened 1 month ago
Looks like we could call setPlayWhenReady(true) in order to request audio focus (see similar resumePlayback()
in ReactExoPlayerView.kt
). Will try this.
The implementation is more difficult than this.
Additionally if RNV continues playing after the scenario above, it does not pause when other audio starts playing.
After implementing an audio manager and listener in the VideoPlayerService, I still reproduced these bugs. This makes me think of abstracting the service. Will continue to implement a first fix.
This leads me The audio listening must even
@paulrinaldi Thank you for sharing you investigations 🙏
Thank you for your bug report. We will review it and get back to you if we need more information.
There is a newer version of the library available. You are using version 6.6.3, while the latest stable version is 6.6.4. Please update to the latest version and check if the issue still exists.
Note: If the issue still exists, please update the issue report with the latest information.
On android 14+ I realized that handleCommand is not receiving the toggle play event because notifications are build automatically on anything Tiramisu and higher so I need to look into what happens on android 14+.
For android 12-, Added a request but this request is not being accepted unfortunately to get control.
For android 14+, Still wondering why onPause and onPlay in the callback say they do not override anything so I commented them out.
So still not working on either.
Thesis for both is that both do not call requestAudioFocus, biggest struggle I'm facing is implementing that call given my unfamiliarity with Kotlin and Android. https://github.com/paulrinaldi/react-native-video/commit/a94707f7c2f1b9aaf0dd64d5374af4185073add5
Realized that focus is manually managed by the code in this library instead of letting exoplayer manage itself. Attempts to manually request focus though are failing to work and adding a listener in the service is also not effective.
Using just the exoplayer works well; testing setAudioAttributes(audioAttributes, true);
instead of setAudioAttributes(audioAttributes, false);
showed correct responses to an incoming phone call, outgoing phone call, and interruptions from youtube (though, I also made other changes see below). All AC's pass. Will continue to test this with a patch in my project but I wonder if there could be a manual way to implement this. Had much trouble doing that.
So if I let exoplayer handle its own pausing and playing due to interruptions, I can't detect interruptions manually for altering the external controls I have (e.g. to sync up for after youtube interrupts a video that is playing in the background).
I let exoplayer handle its own interruptions and just use the playback state change handler to ensure my external video controls nearby the player component to be synced on Android. Unfortunately, this means that after a phone call, the video does not resume. This is still better than the problem experienced earlier.
Any ideas?
"Note: If you use ExoPlayer, consider letting ExoPlayer automatically manage audio focus by calling setAudioAttributes with true for the handleAudioFocus parameter. With this behavior enabled, your app shouldn't include any code for requesting or responding to audio focus changes." - https://developer.android.com/media/optimize/audio-focus
Given this information, specifically that last line "or responding to audio focus changes", I would be suspicious for an audio listener to even detect an audio focus change event - however it may. I will explore this today because resumption after a phone call is the previous experience my users expect with react-native-video.
This issue is stale because it has been open for 30 days with no activity. If there won't be any activity in the next 14 days, this issue will be closed automatically.
Version
6.6.3
What platforms are you having the problem on?
Android
System Version
14
On what device are you experiencing the issue?
Real device, Simulator
Architecture
Old architecture
What happened?"
Original issue title: Tapping UnPause in Notification Media Controls does not pause external media
Notification Controls do not pause non-RNV media that is currently playing (e.g. YouTube). Additionally, if RNV continues playing after the scenario above, it does not pause when other audio starts playing.
Reproduction Link
https://github.com/TheWidlarzGroup/react-native-video/tree/master/examples/basic
Reproduction
Step to reproduce this bug are:
examples/basic/src/VideoPlayer.tsx
's rnv videoplayer component's propplayInBackground={false}
toplayInBackground={true}
yarn run android
with a simulator open (video player app opens)Actual Result:
Expected Result: