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
Bugfix: Interruption ended #115
Bugfix: Interruption ended #115
Conversation
…umable source ended
happened when an interruption with no shouldResume option ended.
this did not forward the interruption ended event and the pausedForInterruption flag would never be removed.
resolves #66
flag is only used while state isPaused anyway
# Conflicts: # AudioPlayer/AudioPlayer/player/AudioPlayer.swift
SwiftLint found issuesWarnings
Errors
Current coverage for AudioPlayer.framework is
|
Files changed | - | - |
---|---|---|
AudioPlayer+Control.swift | 8% |
💀 |
AudioPlayer+PlayerEvent.swift | 23% |
💀 |
AudioPlayer.swift | 27% |
🚫 |
PlayerEventProducer.swift | 94% |
✅ |
Powered by xcov
Generated by 🚫 Danger
Codecov Report
@@ Coverage Diff @@
## master #115 +/- ##
==========================================
- Coverage 72.58% 72.43% -0.15%
==========================================
Files 39 39
Lines 2783 2790 +7
==========================================
+ Hits 2020 2021 +1
- Misses 763 769 +6
Continue to review full report at Codecov.
|
Looks to me that |
@@ -70,7 +70,7 @@ class PlayerEventProducer: NSObject, EventProducer { | |||
case progressed(CMTime) | |||
case endedPlaying(Error?) | |||
case interruptionBegan | |||
case interruptionEnded | |||
case interruptionEnded(Bool) |
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'd be great if you add a label for this param, like .interruptionEnded(shouldResume: Bool)
, so it's clear that the Bool is not about the fact that the interruption ended, but what to do after.
case .interruptionEnded where pausedForInterruption: | ||
if resumeAfterInterruption { | ||
case .interruptionEnded(let shouldResume) where pausedForInterruption: | ||
if resumeAfterInterruption && shouldResume { |
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.
Instead of checking two properties that more or less means the same, is there a possibility that shouldResume variable affects the value of resumeAfterInterruption before arriving to this point, so all the logic is centralised in one place? Usually, when I start having several boolean flags in a class, I start thinking if I can model things better with just an enum variable that gets changed when different events happen, having all the state changes occurring in one function, avoiding possible inconsistencies. Also, this helps checking for this value later, because you don't have to remember of the flags and merge them, that job is already done. What do you think?
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.
resumeAfterInterruption is a configuration for clients, if they want to enable the resume feature
So in my opinion it is distinct enough to check them both together like this.
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.
Yup, makes sense!
Yeah, I think I agree. I've added a comment to one piece of this PR regarding this. It seems to me that having all these flags/variables with almost the same meaning but coming from different places is difficult to handle, because you can forget to update or check some of them. I'd rather have a single place with the state of the class, a list of different actions/events that can happen, and only one function that takes those actions and create a new state, centralised. What do you guys think? |
@danielmartinprieto I agree that state variables and handling is way too fragmented and chaotic right now. But improved state handling should be done in a separate PR than this. Preferably as a new extension to AudioPlayer. |
@ddfreiling Also agree ✨ |
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.
Sorry for the delay! Looks good thanks for your work.
@delannoyk Good to see you back, what was your thoughts on this Kevin? I wanted to add it to this PR if you agreed.
|
@ddfreiling Oh yea we should, it totally makes sense. |
@delannoyk Cool, I'll add a PR for this when I get time. I actually stumbled on a real edge-case bug with
Resetting these on currentItem change should fix this, however edge-case it might be 😄 |
This fixes #66
pausedForInterruption
flag set indefinitely.pausedForInterruption
is now reset on resume, currentItem set, and on any interruptionEnded callback, whether it has the shouldResume option or not.@delannoyk this commit I need feedback on, am I correct that the check on
pausedForInterruption
flag is unnecessary inshouldResumePlaying
?