I am using RXSwift to handle with a lot of async AVAssetWriterInput write operations, but I need to wait for isReadyForMoreMediaData before writing more buffers inside the file, how can I handle this?
Basically, the observable receives a lot of buffers emitted by the asyncWriterSubject and I want to write all of them in the order that I am receiving.
I have this subject:
private var asyncWriter = ReplaySubject<(AVAssetWriterInput,CMSampleBuffer)>.create(bufferSize: 1)
I emit the values for it using this code:
asyncWriter.onNext((videoWriterInput, buffer))
And I am subscribing it here to listen:
disposable = asyncWriter.asObservable()
.takeWhile {
(writerPointer, _) in
writerPointer.isReadyForMoreMediaData
}.observeOn(MainScheduler.asyncInstance)
.subscribe(onNext: { (writerPointer, buffer) in
writerPointer.append(buffer)
})