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 :

  1. the file recorded exists on disk expected
  2. the file can played player : mac, iphone (i imported via itunes), seems good.
  3. the file @ correct location when setup avaudioplayer.
  4. 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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -