Multiple AVAssetWriter Sessions and the Status Property

I am trying to create several consecutive recording sessions using AVAssetWriter. As soon as I completed one successful (after calling finishWriting), the status is set to 2 (AVAssetWriterStatusCompleted).

Trying to create another session, I call startWriting, but I get an error:

[AVAssetWriter startWriting] cannot call method when status is 2 

It seems I can’t create a recording session unless I set up something. Should I recreate AVAssetWriter again? Something is missing for me, and the documents do not help.

Thanks.

+7
source share
1 answer

After the writer has finished, he is no longer used. You must create a new one. From the docs:

You can use only one instance of AVAssetWriter to write to a single file. If you want to write to files several times, you must use a new instance of AVAssetWriter each time.

I have an application in which I use two AVAssetWriters. I create two authors in which only one is active at a time. When some time delta is reached, I click on the active script on the GCD queue to complete and rest and set the active recording pointer to another author.

 if(time > delta) dispatch( ^{ finish writer, create new one }) active_writer = next writer 

This works well when using a capture queue. You can configure the switch to perform operations based on the recording status.

+17
source

All Articles