Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): HLS DVR media should update playable duration in the background #4105

Conversation

paulrinaldi
Copy link
Contributor

@paulrinaldi paulrinaldi commented Aug 21, 2024

e.g. wait until onDestroy

When unmounting a component holding the the videoplayer from RNV component, I saw an error that crashed my app: deleting the notification channel while the foreground service is still running is not allowed.

Summary

Use service starting methods properly. Remove notification channel properly.

Motivation

The exploration started from looking in to #4039 which describes that HLS DVR streams stop loading playable duration when in the backgrond.
Add startForegroundService since the foreground service seemed to not be working correctly, warning logs I saw about buffer deallocations and windows closing and observations above in #4039, and https://stackoverflow.com/questions/45525214/are-there-any-benefits-to-using-context-startforegroundserviceintent-instead-o. Add startForeground (required by using startForegroundService).

Changes

See PR diff.

Test plan

Test on physical android devices with the diff below and HLS DVR streams ("https://democracynow-hls.secdn.net/democracynow-live/play/democracynow.smil/playlist.m3u8", "https://5b44cf20b0388.streamlock.net:8443/dvr/dvr/playlist.m3u8?DVR").

Open the examples/basic videoplayer project, edit with this diff:
background.patch
Also add HLS DVR streams to general.ts to view other than the HLS nonDVR redbull stream.

@@ -95,6 +96,10 @@ class VideoPlaybackService : MediaSessionService() {

override fun onDestroy() {
cleanup()
val notificationManager: NotificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't it be better to move this part of code inside cleanup function ? clean up is used more intensivelly then onDestroy ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would cause a problem because the foreground service/notification could be still alive when cleanup() is ran. I can test this though and report back.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact I am disturbed by the logic.
Notification channel is created in onUpdateNotification and destroyed in onDestroy

For exemple shouldn't you add this code also in : (which calls cleanup)
unregisterPlayer(player: ExoPlayer) {

in fact (maybe), you need to replace cleanup() by hideAllNotifications() in onTaskRemoved and unregisterPlayer() ?

Notice that if you unregisterPlayer and registerPlayer just after the notification channel is not re created...

onDestroy seems ok for me to cleanup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulrinaldi gentle reminder on this point, It would be great to merge this PR for next release !

@freeboub
Copy link
Collaborator

freeboub commented Sep 5, 2024

should decrease repeatability of #3897

@cordovalegacy
Copy link

@freeboub @paulrinaldi my team has had tons of users reporting this issue, could we please get this fix merged so we can update with the fix? Thanks

@jdredman
Copy link

Our app is experiencing this issue and we really need this to improve our UX. Any idea when we can expect a fix?

@roliverplate
Copy link

Hi,
I’d like to emphasize the importance of this fix. We're relying on this update to resolve a key issue in our app, and we're currently facing a critical deadline. The fix is blocking us, so we’d greatly appreciate it if this could be prioritized ASAP.
Thanks for all your hard work!

@freeboub
Copy link
Collaborator

I have one remaining comment, but I am Ok to merge it.
@KrzysztofMoch can you please review this PR ?

@paulrinaldi
Copy link
Contributor Author

Currently using a patch with this as the fix. In a submission to the play store, we did see some crashes when a test user from google play seemed to create a race between reusing and destroying a media session and when trying to play two videos at once. I would recommend we carefully consider the destruction and creation method details.

@freeboub
Copy link
Collaborator

@paulrinaldi Thank you for the feedback! I think the 2 video in parallel is not necessary a usual use case.
If you confirm this patch is better than master branch let's go with it. (I think it is better, just the last comment disturbing me)

Copy link
Member

@KrzysztofMoch KrzysztofMoch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It Okay for me, would be nice to resolve @freeboub comment but not required for this PR

@paulrinaldi
Copy link
Contributor Author

The patch I'm using is still equivalent to the changes in these commits.

@KrzysztofMoch KrzysztofMoch merged commit 40872f5 into TheWidlarzGroup:master Oct 3, 2024
3 checks passed
sharnik pushed a commit to brains-and-beards/react-native-video that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants