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

Videos stop playing when locked, because Libretube is put to sleep #5141

Open
3 tasks done
lu4p opened this issue Nov 12, 2023 · 12 comments
Open
3 tasks done

Videos stop playing when locked, because Libretube is put to sleep #5141

lu4p opened this issue Nov 12, 2023 · 12 comments
Labels
bug Something isn't working help wanted Looking for help wontfix

Comments

@lu4p
Copy link
Contributor

lu4p commented Nov 12, 2023

Steps to reproduce

  1. Play any video
  2. Lock your screen
  3. Wait 5 minutes (This may depend on how aggressive the device is with power management)

Expected behavior

Video should continue playing.

Actual behavior

Video stops playing.

LibreTube version

0.19.0

Android version

Android 13

Other details

This is because Libretube needs to acquire a wakelock https://developer.android.com/training/scheduling/wakelock
in order for Android to not put Libretube to sleep after a few minutes.

Exoplayer can acquire this wakelock for us when it makes sense (i.e. video playing while the screen is off), so I thought I had a 10 line fix for this.

// for online usage
player.setWakeMode(WAKE_MODE_NETWORK)
// for offline usage
player.setWakeMode(WAKE_MODE_LOCAL)

https://developer.android.com/reference/androidx/media3/exoplayer/ExoPlayer#setWakeMode(int)

However when debugging afterwards I learned that exoplayer can only do this when it runs in a service like is already done in the audio player.

This should probably be implemented by extending the Offline and OnlinePlayerServices to also support video, and offloading all PlayerFragement player interactions to it.

The officially recommended solution is a mediasessionservice, however that would require a major refactor which is probably not something that can be easily done (I tried and failed miserably, but I also know little about android development).

I will send a PR to fix the audio player, it is less affected because it is already running as a foreground service, but will also be put to sleep after a longer interval or when Battery Saver is active.

I'm also trying to fix the video player but I'm not sure if I will succeed.

Acknowledgements

  • I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open issue.
  • I have written a short but informative title.
  • I will fill out all of the requested information in this form.
@lu4p lu4p added the bug Something isn't working label Nov 12, 2023
@Bnyro Bnyro added help wanted Looking for help wontfix labels Nov 12, 2023
@Bnyro
Copy link
Member

Bnyro commented Nov 12, 2023

PRs welcome, as I already said I don't have interest in working on that since the audio only mode is good enough for the purpose of background playback.

@lu4p
Copy link
Contributor Author

lu4p commented Nov 12, 2023

This issue is only about videos stopping after a few minutes, after you lock your device. So 7.

@Pamilg8
Copy link
Contributor

Pamilg8 commented Nov 12, 2023

This issue is only about videos stopping after a few minutes, after you lock your device. So 7.

Didn't you just fixed an audio player?

@lu4p
Copy link
Contributor Author

lu4p commented Nov 12, 2023

Yes, but this issue is also about the video player audio was just a lot easier.

@lu4p
Copy link
Contributor Author

lu4p commented Nov 12, 2023

@Pamilg8 do all of the issues you found already have github issues?

@Pamilg8
Copy link
Contributor

Pamilg8 commented Nov 12, 2023

@Pamilg8 do all of the issues you found already have github issues?

I dont know.This PR can also solve background playback issues when exiting the app and browsing other apps.Also restarting the player when you return to the player while background playback is paused will fix the problem.Because, isn't it the same problem?🤔

@ksh-b
Copy link

ksh-b commented Nov 13, 2023

For me the app crashes after a while when I lock the screen. This is the stacktrace shown after starting the app again. Im on android 14, app ver: 0.19.0
https://pastebin.com/DGyqziLu

@alejandro-alzate
Copy link

this could be fixed adding an exception on the battery settings so i doesn't get closed, and letting it linger under the radar.
try that and how it goes

@ksh-b
Copy link

ksh-b commented Nov 14, 2023

this could be fixed adding an exception on the battery settings so i doesn't get closed, and letting it linger under the radar. try that and how it goes

Happens with unrestricted battery usage too

@alejandro-alzate
Copy link

so i can't suggest anything, may helps giving libretube permissions through adb or root but i don't think that libretube can get advantage of root permissions so well i can't help with that your phone seems be very restrictive on that but in mine was fixed with that.

@furrydaemon
Copy link

I would recommend that if libretube is able to know if it has been send to the background or not, to convert the current session (video) to audio, it would probably save battery and mobile data
I don't know if it's the default behaviour or not, I think it is for newpipe

@cbiere
Copy link

cbiere commented Mar 24, 2024

On my device it just takes just 20 seconds until playback stops, if LibreTube is just in the background. There seems to be no effect if PiP is enabled or the screen is turned off.

LibreTube 0.22.1
Android 14 (PixelOS)
Redmi Note 10 Pro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Looking for help wontfix
Projects
None yet
Development

No branches or pull requests

7 participants