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

Fixes issue with not recalculated volume bar frame #17

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Changes from all commits
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
6 changes: 1 addition & 5 deletions Source/SubtleVolume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public enum SubtleVolumeError: Error {
open static let DefaultVolumeStep: Double = 0.05

private var audioSessionOutputVolumeObserver: Any?
private var reenableOutputVolumeObservationWorkItem: DispatchWorkItem?

@objc convenience public init(style: SubtleVolumeStyle, frame: CGRect) {
self.init(frame: frame)
Expand Down Expand Up @@ -171,20 +170,17 @@ public enum SubtleVolumeError: Error {

// If user opted out of animation, toggle observation for the duration of the change
if !animated {
reenableOutputVolumeObservationWorkItem?.cancel()
audioSessionOutputVolumeObserver = nil

updateVolume()

reenableOutputVolumeObservationWorkItem = DispatchWorkItem { [weak self] in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1) { [weak self] in
guard let `self` = self else { return }
self.audioSessionOutputVolumeObserver = AVAudioSession.sharedInstance().observe(\.outputVolume) { [weak self] (audioSession, _) in
guard let `self` = self else { return }
self.updateVolume(Double(audioSession.outputVolume), animated: true)
}
}

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.1, execute: reenableOutputVolumeObservationWorkItem!)
} else {
updateVolume()
}
Expand Down