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

Prevent external audio stopping #25

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions Sources/SwiftFortuneWheel/SwiftFortuneWheel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ public extension SwiftFortuneWheel {
self.animator.addRotationAnimation(fullRotationsCount: 0,
animationDuration: animationDuration,
rotationOffset: rotation,
completionBlock: nil)
completionBlock: { _ in
self.pauseAllSound()
Copy link
Owner

Choose a reason for hiding this comment

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

Calling pauseAllSound after the rotation animation stops is a bad idea. Same audio effects could have more than 1-second duration, and stopping all sound will cut the sound instantly, making sound playback unnatural.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll come up with other suggestion if there is any from my side

})
}


Expand All @@ -429,7 +431,9 @@ public extension SwiftFortuneWheel {
self.animator.addRotationAnimation(fullRotationsCount: 0,
animationDuration: animationDuration,
rotationOffset: rotationOffset,
completionBlock: nil)
completionBlock: { _ in
self.pauseAllSound()
})
}


Expand All @@ -443,7 +447,13 @@ public extension SwiftFortuneWheel {

DispatchQueue.main.async {
self.stopRotation()
self.animator.addRotationAnimation(fullRotationsCount: fullRotationsCount, animationDuration: animationDuration, rotationOffset: rotationOffset, completionBlock: completion, onEdgeCollision: { [weak self] progress in self?.impactIfNeeded(for: .edge)
self.animator.addRotationAnimation(fullRotationsCount: fullRotationsCount, animationDuration: animationDuration, rotationOffset: rotationOffset, completionBlock: { finished in
if finished {
self.pauseAllSound()
}
completion?(finished)
}, onEdgeCollision: { [weak self] progress in
self?.impactIfNeeded(for: .edge)
self?.onEdgeCollision?(progress)
})
{ [weak self] (progress) in
Expand Down Expand Up @@ -523,6 +533,7 @@ public extension SwiftFortuneWheel {
/// Stops rotation animation
func stopRotation() {
self.animator.stop()
self.pauseAllSound()
}

/// Starts rotation animation and stops rotation at the specified index and rotation angle offset
Expand Down