martykan / webTube

Android wrapper for the YouTube website with a couple little tweaks.
GNU General Public License v3.0
96 stars 40 forks source link

Lock the screen-off #93

Open ildar opened 6 years ago

ildar commented 6 years ago

The app is good and quite complete except 1 thing: a video app must hold the screen off. Please?

M1Aston commented 6 years ago

Yes, the screen shuts off while the video is playing. That's not right for a video player. Please fix this.

mvglasow commented 3 years ago

Same here, version 1.2 from F-Droid on LineageOS 18.1 (Android 11).

122 seems to have the same root cause: the screen just dims instead of turning off when the device is plugged in and set to stay awake while charging in developer settings. The dimming would normally occur a few seconds before the screen turns off. The dev setting keeps the screen from turning off, but not from dimming.

After exploring the boundaries of this issue, it seems this behavior only occurs under certain circumstances, namely if the screen is rotated or if immersive mode is enabled/disabled while the video is already playing. As a workaround, pausing and restarting the video after rotating or toggling immersive mode will keep the screen on.

My suspicion is that the app is designed to keep the screen on while playing, but the implementation is buggy. Rotating by 90° will destroy and recreate the activity (a 180° rotation may not, as dimensions do not change); presumably toggling immersive mode also recreates the activity. Presumably, the flag to keep the screen on is set when playback starts and cleared when it ends, but is attached to the main activity or one of its views (e.g. by means of View.keepScreenOn(true)). Therefore, it is lost when the activity (or the view on which the flag was set) is discarded and recreated. The solution would then be to store the playback with the state of the activity (or somewhere outside the activity instance), and restore it when the activity is recreated.