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

Fix auto play when skipping last #2037

Merged
merged 5 commits into from
Aug 16, 2024

Conversation

SergioEstevao
Copy link
Contributor

@SergioEstevao SergioEstevao commented Aug 14, 2024

| 📘 Part of: # |
|:---:|

Fixes #2019

Updates the code to make sure that auto-play logic and other end of episode logic is activated when skip last is triggered.

To test

  • Start the app
  • Ensure that you have Auto-Play active ( Profile -> Settings -> General -> Autoplay )
  • Clean your Up Next Queue
  • Subscribe to a podcast
  • On the podcast page tap on the cog icon on the top right
  • Setup a Skip Last time. Ex: 15 seconds
  • Ensure that podcast has multiple episodes available
  • Play an episode of the podcast
  • Skip forward near to the skip last interval
  • await for the skip last to kick in
  • see if the auto-play works and a new episode of the same podcast is added to your queue and starts playing.

Checklist

  • I have considered if this change warrants user-facing release notes and have added them to CHANGELOG.md if necessary.
  • I have considered adding unit tests for my changes.
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@SergioEstevao SergioEstevao added the [Type] Bug Used for issues where something is not functioning as intended. label Aug 14, 2024
@SergioEstevao SergioEstevao requested a review from a team as a code owner August 14, 2024 18:32
@SergioEstevao SergioEstevao requested review from leandroalonso and removed request for a team August 14, 2024 18:32
@SergioEstevao SergioEstevao added this to the 7.70 ❄️ milestone Aug 14, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Aug 14, 2024

1 Warning
⚠️ This PR is assigned to the milestone 7.71. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@@ -1352,6 +1352,7 @@ class PlaybackManager: ServerPlaybackDelegate {
} else {
FileLog.shared.addMessage("Skipping last \(timeRemaining) seconds of episode because podcast has skip last of \(skipLast) set.")
StatsManager.shared.addAutoSkipTime(timeRemaining)
playerDidFinishPlayingEpisode()
EpisodeManager.markAsPlayed(episode: episode, fireNotification: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergioEstevao Is the call to EpisodeManager.markAsPlayed() still needed? I think all the episode cleanup is already done via playerDidFinishPlayingEpisode().

Also, this will fix the bug for Skip Outro, but not the similar bug when episode is marked as played from Mini Player or Episode list. It would be good to fix all instances, if possible.

Copy link
Member

@leandroalonso leandroalonso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergioEstevao as @rviljoen mentioned I think we have duplicate calls with this change.

Also, following his comment, we could try to fix that in all instances. I played a bit with it and came up with this diff.

It involves adding a new notification and handling it accordingly. This should fix all instances: the reported bug, marking as played (from miniplayer or anywhere else).

We would need to test a bit more to make sure we haven't introduced any regression though.

@rviljoen
Copy link
Contributor

Hi @leandroalonso - I think your approach can work well. You will just need to do the same for EpisodeManager.archiveEpisode.

The other idea I had was to insert a call to autoPlayIfNeeded() in this method before line 551:

func removeIfPlayingOrQueued(episode: BaseEpisode?, fireNotification: Bool, saveCurrentEpisode: Bool = true, userInitiated: Bool = false) {
if userInitiated, let episode {
AnalyticsEpisodeHelper.shared.episodeRemovedFromUpNext(episode: episode)
}
if isNowPlayingEpisode(episodeUuid: episode?.uuid) {
if queue.upNextCount() > 0 {
playNextEpisode(autoPlay: playing())
} else {
endPlayback(saveCurrentEpisode: saveCurrentEpisode)
}
return
}
if let episode = episode {
queue.remove(episode: episode, fireNotification: fireNotification)
}
}

I did some quick testing and I think it covers all the cases. In addition I think it is a low risk change, because the only thing that method call does is to add a single episode to the queue if the queue is empty and autoPlay is enabled. Rest of the app logic remains the same.

@leandroalonso
Copy link
Member

I did some quick testing and I think it covers all the cases. In addition I think it is a low risk change, because the only thing that method call does is to add a single episode to the queue if the queue is empty and autoPlay is enabled. Rest of the app logic remains the same.

Oh, nice! Agree that's a best approach and less risky!

@bjtitus bjtitus modified the milestones: 7.70 ❄️, 7.71 Aug 15, 2024
@bjtitus bjtitus changed the base branch from release/7.70 to trunk August 15, 2024 18:35
@SergioEstevao
Copy link
Contributor Author

SergioEstevao commented Aug 16, 2024

The other idea I had was to insert a call to autoPlayIfNeeded() in this method before line 551:

@rviljoen thanks for the suggestion

So you believe with that change we don't need to do any other change? or this is in conjunction with Leandro changes?

@rviljoen
Copy link
Contributor

The other idea I had was to insert a call to autoPlayIfNeeded() in this method before line 551:

@rviljoen thanks for the suggestion

So you believe with that change we don't need to do any other change? or this is in conjunction with Leandro changes?

I think that one liner covers all the cases without the need for any other code changes. Please check my logic though 😄

@SergioEstevao
Copy link
Contributor Author

@leandroalonso I update the code with @rviljoen suggestion. I tested it with the following scenarios:

  • Skip Last activated and then let the time get to the skip period
  • Mark as played on Episode List and Mini-Player
  • Sleep time active to the end of episode and Skip last active

It looks it's working correctly on the above do you mind give it another look?

Copy link
Contributor

@rviljoen rviljoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Member

@leandroalonso leandroalonso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SergioEstevao one last thing: you can remove the autoplayIfNeeded() in line 978.

@rviljoen
Copy link
Contributor

@SergioEstevao one last thing: you can remove the autoplayIfNeeded() in line 978.

I think that one has to stay in for the case where the episode plays to the end without skip outro and when episode is not mark as played/archived by the user.

@SergioEstevao
Copy link
Contributor Author

I think that one has to stay in for the case where the episode plays to the end without skip outro and when episode is not mark as played/archived by the user.

I agree with you @rviljoen . I just tested the above and we need that line to be there for Auto-play to work

@SergioEstevao SergioEstevao merged commit 0f1ce28 into trunk Aug 16, 2024
4 of 6 checks passed
@SergioEstevao SergioEstevao deleted the fix/2019_fix_auto_play_when_skipping_last branch August 16, 2024 14:18
@leandroalonso
Copy link
Member

Ops, my mistake. 🤦

Thank you both!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug Used for issues where something is not functioning as intended.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setting a skip last value causes autoplay to stop working
5 participants