TortugaPower / BookPlayer

Player for your DRM-free audiobooks
GNU General Public License v3.0
1.57k stars 190 forks source link

Screen stays awake during playback if plugged into power #558

Open baron opened 3 years ago

baron commented 3 years ago

🌎 Environment

💬 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

GianniCarlo commented 3 years ago

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 👍

baron commented 3 years ago

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.

GianniCarlo commented 3 years ago

@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(?)

baron commented 3 years ago

@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.

Sofrus commented 1 year ago

I encountered the same problem

schiko26 commented 9 months ago

I have the same problem.

chrissar commented 6 months ago

I am having the same issue, same reproduction steps.

Murcl commented 4 months ago

I am having the same problem

hrdm4567 commented 4 months ago

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.