Skip to content

Instantly share code, notes, and snippets.

@mingsai
Created July 2, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mingsai/7f76c03cbbe1d6f7c53d to your computer and use it in GitHub Desktop.
Save mingsai/7f76c03cbbe1d6f7c53d to your computer and use it in GitHub Desktop.
An AVAudioSession delegate to manage audio session events and an extension to the AVAudioSession to manage convenient setup for various audio profiles
//
// MNGAVAudioSessionExtensions.swift
//
//
// Created by Tommie Carter on 6/30/15.
// Copyright © 2015 MING Technology. All rights reserved.
//
import AVFoundation
class MNGAVAudioSessionExtensions: NSObject, AVAudioSessionDelegate {
func beginInterruption() {
//
}
func endInterruption() {
//
}
func endInterruptionWithFlags(flags: Int) {
//
}
func inputIsAvailableChanged(isInputAvailable: Bool) {
//
}
}
extension AVAudioSession {
func configureSpokenRecordingSession (){
do {
try self.setCategory(AVAudioSessionCategoryPlayAndRecord)
print ("session category set to \(self.category)")
} catch let e as NSError {
print("could not set session category")
print(e.localizedDescription)
}
do {
try self.setActive(true)
print ("session active status set to \(self)")
} catch let e as NSError {
print("could not make session active")
print(e.localizedDescription)
}
}
func configureSpokenPlaybackSession () {
do {
try self.setCategory(AVAudioSessionCategoryPlayback)
} catch let e as NSError {
print(e.localizedDescription)
print("could not set session category")
}
do {
try self.setActive(true)
} catch let e as NSError {
print(e.localizedDescription)
print("could not make session active")
}
}
func configureMusicPlaybackSession() {
}
func configureMusicRecordingSession() {
}
func audioVolumeChangeListenerCallback () {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment