简体   繁体   中英

AVAssetWriter multiple sessions and the status property

I am attempting to create multiple, serial writing sessions with AVAssetWriter. Once I've completed one successfully (after calling finishWriting) the status is set to 2 (AVAssetWriterStatusCompleted).

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

[AVAssetWriter startWriting] cannot call method when status is 2

Seems I cannot create a writing session unless I configure something. Do I have to recreate the AVAssetWriter again? I must be missing something, and the docs aren't helping.

Thanks.

After the writer has completed it is no longer usable. You must create a new one. From the docs:

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

I have an app where I use two AVAssetWriters. I create two writers where only one is active at a time. When some time delta is reached I push the active writer onto a GCD queue for completion and recreation, and set the active writer pointer to the other writer.

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

This works well when using a capture queue. You can setup a switch to perform the operations given the state of the writer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM