ios - AVAudioPlayer not responding in the background -
i'm playing audio in background when app receive voip notification. avaudioplayer acting weird , play audio , not without error. thats how play:
func playaudio() { // set sound file name & extension let alertsound = nsurl(fileurlwithpath: nsbundle.mainbundle().pathforresource("testaudio", oftype: "wav")!) // play sound { try audioplayer = avaudioplayer(contentsofurl: alertsound) audioplayer.delegate = self if (audioplayer.preparetoplay()) { audioplayer.play() } else {nslog("there error")} } catch { nslog("there \(error)") } }
i initialize avaudiosession in appdelegate application function:
{ audioplayer = avaudioplayer() audiosession = avaudiosession() try audiosession.setcategory(avaudiosessioncategoryplayandrecord, withoptions: [avaudiosessioncategoryoptions.mixwithothers]) try audiosession.setactive(true) try audiosession.overrideoutputaudioport(avaudiosessionportoverride.speaker) } catch { nslog("there \(error)") }
and of course var audioplayer: avaudioplayer!
class verb
its working first minute or 2 , avaudioplayer stop responding without error. try use avaudioplayerdelegate receive events, nothing happen.
can explain behavior? bug in ios? or i'm doing somthing wrong? tested on ios 9.2, iphone 6 device, xcode 7.2.
thanks.
Comments
Post a Comment