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

[iOS] Auto sleep timer #260

Open
GeorgeHahn opened this issue Jun 26, 2022 · 28 comments
Open

[iOS] Auto sleep timer #260

GeorgeHahn opened this issue Jun 26, 2022 · 28 comments
Labels
enhancement New feature or request

Comments

@GeorgeHahn
Copy link

Is your feature request related to a problem? Please describe.

I sometimes forget to enable the sleep timer before falling asleep. It can be difficult to find the right place to rewind to after this happens.

Describe the solution you'd like

A setting to automatically activate the sleep timer during certain hours would help avoid these runaway listening sessions.

Describe alternatives you've considered

The play/pause history feature discussed in other issues could help solve this pain point in a different way.

Additional context

At least one other audiobook app supports this (Listen Audiobook Player on Android).

@GeorgeHahn GeorgeHahn added the enhancement New feature or request label Jun 26, 2022
@advplyr
Copy link
Owner

advplyr commented Aug 7, 2022

Smart Audiobook player also has this feature but they handle sleep timer differently.

I'm not sure the best way to implement this. Would you want to set the time in settings to the time that you want the audio player to pause?

So you might select 22:00 which would then pause media at that time.

The other way would be setting the sleep timer at 22:00 to some length of time like 10 minutes. The problem with that implementation is we would need to add another option to set that length of time or just use a static time.

@GeorgeHahn
Copy link
Author

I really like the way Smart Audiobook player implemented this, with a time range where the sleep timer is automatically enabled.

One potentially interesting option would be to automatically enable the sleep timer when Android's bedtime mode is enabled.

@mefistos
Copy link

Also just having option to have sleep timer enabled by default until turned off manually would be great. When I am listening to audiobooks at night and wake up, I can just press the play button on my headphones to continue listening, but it keeps playing rather than keep the previous sleep settings and stop playing after couple minutes.

@advplyr
Copy link
Owner

advplyr commented Aug 23, 2022

@mefistos Is this how the sleep timer functions in another app you use?

@mefistos
Copy link

mefistos commented Aug 23, 2022

@mefistos Is this how the sleep timer functions in another app you use?

Same as others have mentioned Smart Audiobook Player on Android. As @GeorgeHahn mentioned in SAP you select time range where the sleep timer is always enabled, so for example I have 22:00 till 8:00 and if I am listening in that time the sleep timer always resets and stays on so if I hit play in the middle of the night it turns off after 20 mins. After 8:00 when I am driving or working the sleep timer is off so I can listen for longer.

Or even as I said previously just having option to maybe hold the sleep timer icon for a while to keep it enabled and then hold it again to disable it would be plenty.

@advplyr
Copy link
Owner

advplyr commented Aug 23, 2022

I understand. The sleep timer logic will have to be redone but it seems this is the consensus on what is expected.

@mefistos
Copy link

mefistos commented Aug 23, 2022 via email

@advplyr
Copy link
Owner

advplyr commented Aug 23, 2022

That was just recently added and will be in the next release #322

@advplyr
Copy link
Owner

advplyr commented Aug 23, 2022

That custom sleep timer value won't persist though so it would need to be entered every time it's set.
That probably won't be very useful in your use-case

@mefistos
Copy link

@advplyr No worries, its not end of the world. I like Audiobookshelf so much that I don't mind waiting till sleep timer is rewritten.

@mefistos
Copy link

Hey, I saw the dev-chat in discord and thought of sharing some screens from Smart Audiobook Player to give you a little bit of idea how it deals with sleep timer. When you short press the sleep timer icon you get to set up the schedule when it's active and when you hold the button it let's you select the specific time. You don't have to go to settings to set it up, although you can.

Screenshot_20220829-225134_Smart AudioBook Player
Screenshot_20220829-225107_Smart AudioBook Player

@Strider27
Copy link

Strider27 commented Oct 31, 2022

+1 for this, Smart Audiobook Player implementation is best so far.
Set the default timer in settings to either be permanently enabled or on schedule, so it doesn't have to be set every time. The timer then resets every time the phone is moved and has an audible tone when it is about to go off, if the phone is moved between the beep and fadeout, the timer resets again.

Current timer has two issues for me:

  1. forgetting to set it every time
  2. Timer resets by moving only when the track starts fading out, regardless of whether the phone was last moved a minute ago or when the timer was originally set.

@mefistos
Copy link

I've sent email to the SAP developer with link to ABS api with request to implement support for ABS and he said that he'll think about it. That way we'd have best of both worlds, because lest be honest SAP is hands down the best android Audiobook player out there.

Might be worth for other people sending him an email as well.

@Strider27
Copy link

@mefistos SAP is good, but the native app is almost there. Not sure if SAP dev integrating audiobookshelf API would be a gamechanger for me at this stage, as I doubt it'll be fully integrated with series, progress sync, etc. If he does go ahead with it, it'll be most likely just the browse, stream and download locally functions.
For me personally all that's missing from the current native app is a better timer implementation and the series order field of the locally downloaded books is missing when not connected to server, making it hard to figure out which one to play next when you are away/not connected and have downloaded several books from the same series to your phone.

@Dr-Blank
Copy link

Dr-Blank commented Nov 16, 2022

I came here annoyed of forgetting to put a sleep timer before I sleep. I usually listen to books before sleeping and have forgotten to put a sleep timer, waking up to drained battery and a random position in the book.

As the thread said, it would be great to just auto enable sleep timer during certain hours (as set by user) for the preferred countdown time (also customisable).

I used maBook to listen AB before ABS and here is a screenshot of "Settings>Sleep timer" page in the app just for reference.

Screenshot_2022-11-16-00-28-18-229_mindmine audiobook

What it does is, when I press play during the set hours, it turns on the sleep timer for me.

Thank you for all the effort you have put into this so far.

@Albuca
Copy link

Albuca commented Dec 15, 2022

Throwing in my $0.02

There are really two 'features' that Smart Audiobook Player maintains and keeps it as my primary listening app:

  1. The sleep timer resets when motion is detected. I always have the sleep timer on, set to 15 minutes. When I'm moving around, the timer is always reset to 15 mins -- but when I put the phone down and go to sleep, it will complete its countdown and slowly fade the audio out before pausing. I turned off the 'bing' indicating that the timer has completed, I just let it slowly fade out - or give the phone a shake to continue things on if I am still awake and notice the volume falling.
    Currently, I believe ABS only resets that timer if motion is detected during the fade-out period.

2) A History of Playback is maintained, with play/pause, scrubbing, forward, back, etc. documented along the date/time this occurred. A tap will move the audiobook back to the selected point and resume playback from there (this move will also be documented in the history).
This feature is extremely useful if/when my playback progress is moved by an inadvertent tap, I zoned out and want to go back to the point I was at when I first started my listening session, or just want to go back in time for some reason.

Brought up in this issue: #466 (comment)

Thank you for your continued effort into all things Audiobookshelf!

@linost-xx
Copy link

Great comments so far, and I hope this gets implemented.

Another 'feature' Smart Audiobook player has, is that it will reset the sleep timer when you pause/play. It's great when the phone is on the nightstand and you are using an bluetooth headset or similar to listen.

I also feel that the 'shake to reset' in Audiobookshelf is a bit unsensitive, maybe there could be som more options in the settings were we can tweak the sensitivity.

@linost-xx
Copy link

linost-xx commented Jan 9, 2023

I've added

fun play() {
    if (currentPlayer.isPlaying) {
      Log.d(tag, "Already playing")
      return
    }
    currentPlayer.volume = 1F
    currentPlayer.play()
    sleepTimerManager.handleShake()
    //Reset sleep timer on pause/play if timer is set.
    if (sleepTimerManager.sleepTimerRunning) {
      sleepTimerManager.setSleepTimer(sleepTimerManager.sleepTimerLength, false)
      return
    }
  }

in PlayerNotificationService.kt to implement "reset timer on play" functionality. Obviously I had to change sleepTimerRunning and sleepTimerLength in SleepTimerManager.kt to public so I could access those variables. I'm sure there is a correct way to do this, but I'm a rebel and really needed this functionality=)

@InkyPi
Copy link

InkyPi commented Jan 26, 2023

Man it's nice to find a thread of likeminded people 😂

I've been using SAP for quite a while now and absolutely love how the sleep timer is set up, I'd really like to see a couple of those key features implemented in ABS. Just to clarify, I use a single bluetooth earbud to listen to books before I go to sleep and it has a button on the side I can tap to pause.

The SAP features I particularly like are:

  1. The fadeout is longer (around 30 seconds?) so there isn't a sudden drop in volume. It's far nicer drifting off to sleep if the audio gradually fades away. I'd be happy with it set in the 30 to 60 seconds range, but it would also be cool if there was an option to choose how long the fadeout is.

  2. When I tap my earbud to pause it resets the timer, which is really handy. If I pause to talk to someone, check my phone, get a drink, take a leak etc I am back to heightened level and need to start the process of falling asleep all over again, so it'd be nice if the timer reset at the same time.

  3. If I'm still somewhat lucid when the audio starts to fade, all I have to do is a single tap on my earbud and the volume returns to full and the timer resets. It's a small, but significant feature where tapping the pause button during the fadeout doesn't actually pause the audio, it just resets the timer.

Essentially what I do each night is set my timer for 5 minutes and listen to a book while I fall asleep. Usually I'll tap the earbud 2 or 3 times over the course of 20 minutes or so before finally falling asleep. In the morning I only have to rewind 5 minutes to make sure I didn't miss anything 😃

@advplyr
Copy link
Owner

advplyr commented Jan 29, 2023

I think I covered most of these for the next update. These are only for Android right now but the same logic would apply when implemented on iOS.

Here are the updates:

  1. Shaking the device at any time while a sleep timer is running will reset it (unless you have disabled shake to reset). Shaking the device within 2 minutes of the sleep timer expiring will also reset the sleep timer and start playback.
  2. If a sleep timer is running then pressing play will reset the sleep timer. Pressing play within 2 minutes of the sleep timing expiring will also reset the sleep timer and start playback.
  3. If you have chosen the "End of Chapter" option then resetting the sleep timer will continue to use the end of the chapter. This means if the chapter just finished and paused, then you can shake or pause/play to reset the sleep timer to the end of the next chapter.
  4. Shake sensitivity setting added with Very High, High, Medium, Low, Very Low. Very high means highly sensitive to movement.
  5. Auto sleep timer. When this is enabled a sleep timer will be automatically started when playing media between the start and end time set in settings. The length of the auto sleep timer is set in settings and includes End of Chapter and using a custom time in minutes.
    • Currently if you cancel the sleep timer inside the audio player then it will continue to start again if within the auto sleep timer range. I think I will set this so that if you cancel it then it will remember you canceled it until you change media.
  6. The audio now starts fading out when 60 seconds are remaining on the sleep timer (this was previously 30 seconds).

image

@advplyr advplyr unpinned this issue Jan 29, 2023
advplyr added a commit that referenced this issue Jan 29, 2023
@Strider27
Copy link

Strider27 commented Jan 31, 2023

@advplyr Thanks, You are the best!!!!

2 minor issues with timer reset.

  1. The idea for timer to be reset at any time was that if you are moving etc, it always resets and only starts counting down once we are sedatory. With the latest release even the very low shake sensetivity still requires you to shake the device considerably ( would be nice if there was "move to reset option") although this may not be an issue as I haven't tested it extensively, the very low sensetivity may be just about enough for it to reset during an active enough day.
  2. Can we have an option to disable vibrate every time it resets? During an active day/workout we'll be getting ghost notification every time we move :O it'll drive people bananas 🍌

@RobinD42
Copy link

I think I covered most of these for the next update.

Sounds like some good updates there, and obviously my comment in #320 (comment) should have been here.

One thing not mentioned that I would like to see is an option for a zero fade-out. In other words, don't fade, just pause at the end of the timer or chapter.

@advplyr
Copy link
Owner

advplyr commented Jan 31, 2023

@Strider27 If you set the sensitivity to Very High then just moving the device at all should trigger the reset. If you use Very Low then you will need to give the device a good shake

@Strider27
Copy link

Thanks, I'm stupid haha, for whichever reason assumed it was the other way around.

Any way to turn off vibration every time it is reset?

@advplyr
Copy link
Owner

advplyr commented Jan 31, 2023

Added in v0.9.61-beta for Android.

Will leave this open until implemented on iOS

@advplyr advplyr changed the title [Enhancement] Auto sleep timer [iOS] Auto sleep timer Jan 31, 2023
@Strider27
Copy link

@advplyr I have the v0.9.61-beta but it still vibrates like crazy when reset, have haptic feedback off in settings. Am I missing something?
Screenshot_20230131_223429_audiobookshelf

@advplyr
Copy link
Owner

advplyr commented Jan 31, 2023

Haptic feedback is for the user interface interaction. I will add a separate setting for controlling the sleep timer feedback.

@dedors
Copy link

dedors commented Jun 30, 2023

Thanks a lot for all the effort. It's close to what I like (also a SABP user here).

  • An option to give a sound instead of vibration when sleep timer resets during fadeout. Would also like one when fadeout starts.
  • An option to reset sleep timer on every user interaction, not only play/pause.
  • Add an history entry when playback stop was tiggered by the sleep timer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants