Avqueueplayer Playback Without Gap and Freeze

AVQueuePlayer playback without gap and freeze

The solution is found.

When adding new AVPlayerItem in queue of AVQueuePlayer player will synchronously wait till initial part of player item will be buffered.

So in this case player item should be buffered asynchronously and after that it can be added in the queue.
It can be done using [AVURLAsset loadValuesAsynchronouslyForKeys: completionHandler:]

For example:

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *keys = [NSArray arrayWithObject:@"playable"];

[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^()
{
dispatch_async(dispatch_get_main_queue(), ^
{
AVPlayerItem *playerItem = [[[AVPlayerItem alloc] initWithAsset:asset] autorelease];
[player insertItem:playerItem afterItem:nil];
});

}];

Using this solution queue of AVQueuePlayer can be populated with items without any gaps and freezes.

How to play multiple videos in AVQueuePlayer or AVMutableComposition without any gapes or freeze?

For Ultravisual we used AVMutableComposition, and as long as we built up the composition first and then built a player to play it, we were able to get flawless gap-free playback everywhere except when looping.

Can you walk through all the tracks in your AVMutableComposition and verify there are no gaps? Don't forget the audio tracks. Sometimes audio and video have different timestamps - you may need to add another track to your AVMutableComposition to get around this.

Gapless playback with AVQueuePlayer/AVPlayer - is it possible?

You can use the AVAssetReader or Extended Audio File Services API to read data from the audio files, and then feed uncompressed audio data to an Audio Unit mixer with any desired gap, gapless, overlap, or even mix. Proper use of all these APIs is non-trivial.

AVPlayer streaming stops in background due to gaps

I solved it by using a combination of AVQueuePlayer and AVPlayerActionAtItemEndAdvance.

It is tricky but it works.



Related Topics



Leave a reply



Submit