I work on iOS and i want to read videos files, one after another, without delay between videos.
Also, i must to be able to refresh the playlist while playing (add videos to the queue).
I've tried with AvQueuePlayer, it works fine, i can refresh the playlist, but there is a little delays between each video.
I've tried with AVMutableComposition, there is no delay between video, but i can't refresh the playlist while playing videos.
Exist it any others solutions? with no delays between video, and where i could refresh the playlist?
Thanks.
EDIT :
The code below works, i play some videos files of 0.5 seconds and there is no gap ! But there is an issue, the sound is fine, but the video freezes every time ! Why ?
AVMutableComposition *myCompo = [[AVMutableComposition alloc] init];
for (int countName = 0; countName<10; countName++)
{
//Initialize Asset
NSURL *MyURL = [[NSBundle mainBundle]
URLForResource: [NSString stringWithFormat:@"%d", countName] withExtension:@"mp4"];
AVURLAsset * myAsset = [[AVURLAsset alloc] initWithURL:MyURL options:nil];
//Track AUDIO
AVMutableCompositionTrack *compositionAudioTrack = [myCompo addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionAudioTrack setPreferredVolume:1.0];
AVAssetTrack *clipAudioTrack = [[myAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0];
//Track VIDEO
AVMutableCompositionTrack *compositionVideoTrack = [myCompo addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *clipVideoTrack = [[myAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
//Time lenght
CMTime durationFile = clipAudioTrack.timeRange.duration;
CMTime timeCompo = myCompo.duration;
//Insert TRACK AUDIO
BOOL result = [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, durationFile) ofTrack:clipAudioTrack atTime:timeCompo error:nil];
if(result)
{
NSLog(@"Audio Ok");
}
else
{
NSLog(@"Audio not ok");
}
//Insert TRACK VIDEO
result =[compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, durationFile) ofTrack:clipVideoTrack atTime:timeCompo error:nil];
if(result)
{
NSLog(@"Video Ok");
}
else
{
NSLog(@"Video not ok");
}
}
dispatch_sync(dispatch_get_main_queue(), ^{
player2 = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithAsset:myCompo]];
playerLayer2 = [AVPlayerLayer playerLayerWithPlayer:player2];
playerLayer2.frame = [self view].layer.bounds;
playerLayer2.videoGravity = AVLayerVideoGravityResizeAspectFill;
[[self view].layer insertSublayer:playerLayer2 atIndex:0];
});
[player2 play];