-
Notifications
You must be signed in to change notification settings - Fork 133
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
Sleep Timer: automatically restart if playback is resumed within 5 minutes #1612
Sleep Timer: automatically restart if playback is resumed within 5 minutes #1612
Conversation
We're going to need the last setting when restarting by shaking the phone
} | ||
|
||
func restartSleepTimerIfNeeded() { | ||
guard !PlaybackManager.shared.sleepTimerActive() else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's kinda weird to call PlaybackManager
here while this is injected there, but I thought it would be better to extract extending sleep timer functionality outside of PlaybackManager
, given it's already big and complex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Sleep timer behaved as expected
✅ player_sleep_timer_restarted
was logged
✅ Sleep timer wasn't restarted once I waited past the restartSleepTimerIfPlayingAgainWithin
value
❌ I couldn't get the "Restarting timer for end of episode" function to work like I expected. Playback did end at the end of the episode but the timer set back to End of Episode and playback continued for the second podcast past the end and into the next in queue. I also didn't see the player_sleep_timer_restarted
event logged and didn't hit a breakpoint in SleepTimerManager.playbackTrackChanged
.
✅ Checked timer countdown on Pause & Cancel
Here's a recording of the End of Episode behavior I saw:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-04-11.at.21.34.34.mp4
podcasts/SleepTimerManager.swift
Outdated
Analytics.shared.track(.playerSleepTimerRestarted, properties: ["duration": "end_of_episode"]) | ||
PlaybackManager.shared.sleepOnEpisodeEnd = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leandroalonso 👋🏽 Awesome work!!
Just to double check... According to our Pocket Casts Tracking Plan
sheet, the property for playerSleepTimerRestarted
event should be time
instead of duration
. Is that right? I can use duration
and update the sheet if you wanted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, my mistake! It should be time
so it's consistent with the other events!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 19f6c88
@bjtitus ops, sorry! One change that I made after testing this step and adding the last two caused a regression. Thanks for the thorough testing and spotting that. I updated the code and now it should behave correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything works now!
Thanks, this is awesome, though please also follow up with automatic sleep timer setting during configurable hours, i.e. it should work also if you wait more than 5 mins. |
@bitmanlger this is still in the works! |
Great, looking forward to it :) |
This PR implements a mechanism to restart the sleep timer whenever the user restarts playback within 5 minutes.
I haven't added any confirmation sound because if I'm sleeping I don't feel like hearing a voice or a confirmation sound for the sleep timer, but we can adjust accordingly in the future based on feedback.
To test
To make testing faster, go to
SleepTimerViewController.swift
and change thefiveMinutesTapped
function to5.seconds
(instead of5.minutes
), also go to Profile > Beta Features > and enabletracksLogging
.Restarting timer for a given amount of time
🔵 Tracked: player_sleep_timer_restarted ["duration": 5.0]
is trackedNot restarting timer
Go to
SleepTimerManager.swift
and changerestartSleepTimerIfPlayingAgainWithin
to5.seconds
.Restarting timer for end of episode
Go to
SleepTimerManager.swift
and revertrestartSleepTimerIfPlayingAgainWithin
to5.minutes
.🔵 Tracked: player_sleep_timer_restarted ["duration": "end_of_episode"]
is trackedPausing
Canceling
Checklist
CHANGELOG.md
if necessary.