Created
February 5, 2015 20:57
-
-
Save ubik2/7b718c9ce6796197e0f4 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
func getSampleRate() { | |
var session: AVAudioSession = AVAudioSession.sharedInstance() | |
var audioSessionError: NSError? | |
session.setCategory(AVAudioSessionCategoryPlayback, error:&audioSessionError) | |
if (audioSessionError != nil) { | |
println("Error \(audioSessionError?.code), (audioSessionError?.localizedDescription)") | |
} | |
var bufferDuration = NSTimeInterval(0.005) | |
session.setPreferredIOBufferDuration(bufferDuration, error:&audioSessionError) | |
if (audioSessionError != nil) { | |
println("Error \(audioSessionError?.code), (audioSessionError?.localizedDescription)") | |
} | |
var sampleRate = 88200.0 | |
session.setPreferredSampleRate(sampleRate, error:&audioSessionError) | |
if (audioSessionError != nil) { | |
println("Error \(audioSessionError?.code), (audioSessionError?.localizedDescription)") | |
} | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("handleRouteChange:"), name:AVAudioSessionRouteChangeNotification, object: session) | |
session.setActive(true, error:&audioSessionError) | |
if (audioSessionError != nil) { | |
println("Error \(audioSessionError?.code), (audioSessionError?.localizedDescription)") | |
} | |
sampleRate = session.sampleRate | |
bufferDuration = session.IOBufferDuration | |
println("Sample Rate: \(sampleRate)HZ I/O Buffer Duration:\(bufferDuration)") | |
} | |
func handleRouteChange(object:AnyObject) { | |
println("Got route change for playback") | |
getSampleRate() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment