avfoundation - iOS - Swift - Some audio when recording reached the maximum allowable length -


i implemented video recorder in swift part of ios app, set maxrecordedduration video output 4 seconds (30 frames per second):

self.videooutput?.maxrecordedduration = cmtimemakewithseconds( 4, 30 ) 

when user starts recording there 2 scenarios can occur:

  1. the user decides stop recording before max recording duration reached.
  2. the max recording duration reached before user stops video recording.

in of 2 cases both

func captureoutput( captureoutput: avcapturefileoutput!, didstartrecordingtooutputfileaturl fileurl: nsurl!, fromconnections connections: [anyobject]! ) 

and

func captureoutput( captureoutput: avcapturefileoutput!, didfinishrecordingtooutputfileaturl outputfileurl: nsurl!, fromconnections connections: [anyobject]!, error: nserror! ) 

will triggered part of avcapturefileoutputrecordingdelegate, responsible responding events occur in process of recording video file (corresponding apple documentation).

the video output works flawless in user scenario 1. however, in user scenario 2 video output missing audio bits. in other words, @ end of video, video still playing while there no sound.

i aware when max recording duration reached, func captureoutput( captureoutput: avcapturefileoutput!, didfinishrecordingtooutputfileaturl outputfileurl: nsurl!, fromconnections connections: [anyobject]!, error: nserror! ) throws following error:

error domain=avfoundationerrordomain code=-11810 "recording stopped" userinfo={averrortimekey=cmtime: {120/30 = 4.000}, averrorrecordingsuccessfullyfinishedkey=true, nslocalizeddescription=recording stopped, nslocalizedfailurereason=the recording reached maximum allowable length., nsunderlyingerror=0x175324c0 {error domain=nsosstatuserrordomain code=-16413 "(null)"}}

i added code beginning of method check whether recording still finished when error thrown:

    // error during video recording     if let error = error, let finishedsuccessful = error.userinfo[ avfoundation.averrorrecordingsuccessfullyfinishedkey ] as? bool     {         // video not recorded         if !finishedsuccessful         {             return         }     } 

even though code runs expected, video outcome has missing audio in end mentioned above. wondering if there way fix bug?

not sure fixing bug, there way avoid it. ignore maxrecordedduration feature , build own countdown timer. way make sure scenario 1 possible scenario.

there multiple ways achieve that. simple 1 perform stoprecording() delay of x seconds moment recording started.


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -