BookPlayer icon indicating copy to clipboard operation
BookPlayer copied to clipboard

Screen stays awake during playback if plugged into power

Open baron opened this issue 4 years ago • 10 comments

🌎 Environment

  • OS Version: 14.4
  • Version/Release: 3.11.2-1

💬 Description

So this one is a revisit of #541 which was closed.

The core of the issue is: When BookPlayer is playing it prevents the screen from sleeping.

This is a bug since:

  1. Apple's Music, Spotify, and other audio book apps respect the screen lock settings and go to black even during charging
  2. BookPlayer's behavior is inconsistent and will fade to black if not plugged into power
  3. I have settings "Disable Autolock" OFF and "Only when connected to power" OFF (see hypothesis below)

Additional note: I like using this app to listen to books at night in a dark room to unwind. Having the audio controls always on screen is annoying and kills the immersive experience I seek. It is also very problematic with iOS's tilt to awake feature which easily triggers a lock screen awaken event (I have a wireless charging stand so this always happens).

I was particularly intrigued because this bug only happens while charging.

I've narrowed down a possible trigger in the code for you to investigate:

https://github.com/TortugaPower/BookPlayer/blob/72d881dab5034de16a16d2a1e549fd447a3032bb/BookPlayer/Player/PlayerViewController.swift#L340

If I understand the logic correctly updateAutoLock() will always set UIApplication.shared.isIdleTimerDisabled = true which will prevent screen sleep regardless of settings when power is connected.

Also UIApplication.shared.isIdleTimerDisabled = UIDevice.current.batteryState != .unplugged means that this will default to "true" as long as the phone is being charged and "false" otherwise.

In other words the app's logic prevents UIApplication.shared.isIdleTimerDisabled from being set to false while playback during charging regardless of app settings "Disable Autolock" OFF and "Only when connected to power" OFF.

Although I don't have a pull request or sample project since I'm not an iOS developer I'm fairly confident about the logic. Please consider adding proper setting of UIApplication.shared.isIdleTimerDisabled in accordance with preferences while respecting default system values if possible.

🦶 Reproduction Steps

Steps to reproduce the behavior, provide an example of the command line issued:

  1. Set screen lock to 30 seconds
  2. Play audio
  3. Put on charger
  4. Awaken screen
  5. Screen never sleeps
  6. unplug from charger
  7. screen sleeps after 30 seconds

🤔 Expected Results

I want it to sleep in accordance with the settings app value like other major audio apps including Apple Music.

😲 Actual Results

End up staring at playback time on audio book instead of enjoying book :(

🤝 Relationships

  • Related PRs or Issues: #xxx, #yyy

baron avatar Feb 26 '21 10:02 baron

Hi @baron ! thanks for the detailed investigation and the reproduction steps

~~Regarding the updateAutolock()function~~

https://github.com/TortugaPower/BookPlayer/blob/72d881dab5034de16a16d2a1e549fd447a3032bb/BookPlayer/Player/PlayerViewController.swift#L340-L354

~~The first line checks whether the user has configured the setting and is set to true, otherwise it doesn't continue with the rest.~~

I'll add this to be reviewed in the next sprint next week as well

-- EDIT

Nevermind my comment about the function, I reread your description, I'll check it out next week 👍

GianniCarlo avatar Feb 26 '21 15:02 GianniCarlo

Thank you for giving this your attention, I wish I could be more helpful with actual code but hopefully provided you with enough information to investigate.

I have tipped before but will gladly tip again if this is resolved as I really like the app. I listened to the entire Dark Tower series by Stephen King with this app so it has a special place in my heart. Thank you for giving us such a quality app that is up to date with modern aesthetics and conventions.

baron avatar Feb 26 '21 16:02 baron

@baron I tried reproducing it but with no success. Can you specify in the steps in which screen you're currently at for each one?

Regarding this line UIApplication.shared.isIdleTimerDisabled = UIDevice.current.batteryState != .unplugged the app will only reach that if the user has enabled the Disable Autolock feature, the first guard statement takes care of that. For the version that is waiting for review, I have also included a UIApplication.shared.isIdleTimerDisabled = false before the return of the first guard, it may help in some cases(?)

GianniCarlo avatar Mar 02 '21 23:03 GianniCarlo

@GianniCarlo I'll lookout for the update and report back. Thank you for looking into this. I'll do my best to break it down. Also, I didn't emphasize that I have "tilt to awake enabled" but this didn't affect my testing.

Steps to reproduce the behavior, provide an example of the command line issued:

  1. Settings app - Set screen lock to 30 seconds and Tilt to awake is ON (under screen lock settings)
  2. Open BookPlayer - Play audio book
  3. Lock screen with power button
  4. Put on stand charger or plug in lightning cable
  5. Awaken screen by tilting or pressing home button without unlocking
  6. Lock screen never sleeps
  7. unplug from charger and lay down phone
  8. screen sleeps in several seconds

Also my apologies if my title doesn't make it clear that I'm talking about the lock screen showing book cover and playback controls.

I can also make the screen sleep manually by pressing the power button. But BookPlayer is the only major audio app that shows this behavior.

baron avatar Mar 07 '21 15:03 baron

I encountered the same problem

Sofrus avatar Mar 31 '23 15:03 Sofrus

I have the same problem.

schiko26 avatar Nov 28 '23 16:11 schiko26

I am having the same issue, same reproduction steps.

chrissar avatar Feb 08 '24 20:02 chrissar

I am having the same problem

Murcl avatar Apr 22 '24 22:04 Murcl

I also experience this issue - steps to reproduce are the same as mentioned above. I am on the latest version 5.2.8-49, but have experienced this issue the whole time I've been using BookPlayer (at least a year or two). This app is the only one that exhibits this behavior.

hrdm4567 avatar May 02 '24 09:05 hrdm4567