Created
March 14, 2016 23:08
-
-
Save wh1pch81n/9866cb8e4eace7c2d3bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
class EACAudioManager: NSObject { | |
static let sharedInstance = EACAudioManager() | |
var volumeDidChange = { (newVolume: Float) -> () in } | |
var currentVolume: Float { return AVAudioSession.sharedInstance().outputVolume } | |
override init() { | |
super.init() | |
try! AVAudioSession.sharedInstance().setActive(true) | |
AVAudioSession.sharedInstance().addObserver(self, forKeyPath: "outputVolume", options: NSKeyValueObservingOptions.New, context: nil) | |
} | |
override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) { | |
if let keyPath = keyPath { | |
switch keyPath { | |
case "outputVolume": | |
volumeDidChange(object!.valueForKeyPath(keyPath) as! Float) | |
default:() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment