Skip to content

Instantly share code, notes, and snippets.

// this log is from the run after recompiling by simply clicking the "play" button on xcode
--- playAction
AVAudioSession Category Playback OK
AVAudioSession is inactive
AVAudioSession is Active
--- audioPlayerBeginInterruption
audioPlayer.playing false
AVAudioSession is inactive
AVAudioSession is inactive
// does NOT resume play at all
// what's different = no .MixWithOthers at all
/* console output:
AVAudioSession Category Playback OK
AVAudioSession is Active
handleInterruption
began
audioPlayer.playing false
AVAudioSession is inactive
// does NOT resume play at all
// what's different = .MixWithOthers set with AVAudioSessionCategoryPlayback
/* console output:
AVAudioSession Category Playback OK
AVAudioSession is Active
handleInterruption
began
audioPlayer.playing false
AVAudioSession is inactive
// does NOT resume play at all
// what's different = .MixWithOthers not set with theSession
/* console output:
AVAudioSession Category Playback OK
AVAudioSession is Active
handleInterruption
began
audioPlayer.playing false
AVAudioSession is inactive
// this version resumes play the first time alarm interrupts but the second time will not resume play - sometimes it does not resume play even once
// what's different = using theSession for all the AVAudioSession.sharedInstance() calls
/* console output:
AVAudioSession Category Playback OK
AVAudioSession is Active
handleInterruption
began
audioPlayer.playing false
AVAudioSession is inactive
// this version DOES resume play properly multiple times
// what's different = theSession is used only for setting up .MixWithOthers independently of the AVAudioSession.sharedInstance() used to set up background play (I'm afraid I am unable to explain why this works)
/* console output:
AVAudioSession Category Playback OK
AVAudioSession is Active
handleInterruption
began
audioPlayer.playing false
handleInterruption
@plaudev
plaudev / ViewController.swift
Last active August 6, 2016 04:53
test audio interruption
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player = AVAudioPlayer()
let audioPath = NSBundle.mainBundle().pathForResource("rachmaninov-romance-sixhands-alianello", ofType: "mp3")!
/*