ios - AVAudioPlayer sends "Unsupported file" error when playing a file recorded via AVCaptureSession -
i've been scratching head around full day , don't seem closer, hope guys can guide me in right path :)
heres's situation.
i have avcapturesession initialized add audio input follows :
let audiodevice = avcapturedevice.defaultdevicewithmediatype(avmediatypeaudio) let audioin = try! avcapturedeviceinput(device: audiodevice) if (session.canaddinput(audioin)) { session.addinput(audioin) }
the audio output added follows :
if session.canaddoutput(self.audiooutput) { self.audiooutput = avcaptureaudiodataoutput() session.addoutput(self.audiooutput) self.audioconnection: avcaptureconnection = self.audiooutput.connectionwithmediatype(avmediatypeaudio) }
i setup recording settings :
if let audioassetwriteroutput = self.audiooutput.recommendedaudiosettingsforassetwriterwithoutputfiletype(avfiletypeapplem4a) { return audioassetwriteroutput as? [string: anyobject] }
which assign avassetwriterinput initialized in audio mode, settings , correct format description.
_audioinput = avassetwriterinput(mediatype: avmediatypeaudio, outputsettings: audiosettings, sourceformathint: audioformatdescription) _audioinput!.expectsmediadatainrealtime = true
then start avcapturesession via startrunning()
capture audio data .m4a file.
everything fine during audio capture, here observations made :
- the file recorded exists on disk expected
- the file can played player : mac, iphone (i imported via itunes), seems good.
- the file @ correct location when setup avaudioplayer.
- tried initialize avaudioplayer nsdata or nsurl, same result
now later in code, try read audio file via avaudioplayer :
self.audioplayer = [[avaudioplayer alloc] initwithcontentsofurl:[nsurl fileurlwithpath:pathlink] error:&error];
i thrown error
error domain=nsosstatuserrordomain code=1954115647 "(null)"
which after double checking "unsupported type".
what's incorrect in setup ? come avcapturesession or can wrong avaudioplayer setup ?
thanks !
Comments
Post a Comment