私は iOS で作業しており、ビデオ間で遅延なく、次々とビデオ ファイルを読みたいと思っています。
また、再生中にプレイリストを更新できる必要があります (ビデオをキューに追加します)。
AvQueuePlayer を試してみましたが、問題なく動作し、プレイリストを更新できますが、各ビデオ間に少し遅延があります。
AVMutableComposition で試してみましたが、ビデオ間に遅延はありませんが、ビデオの再生中にプレイリストを更新できません。
他の解決策はありますか?ビデオ間に遅延がなく、どこでプレイリストを更新できますか?
ありがとう。
編集 :
以下のコードは機能します。0.5 秒の動画ファイルをいくつか再生しますが、ギャップはありません。しかし、問題があります。音は問題ありませんが、ビデオは毎回フリーズします! なんで ?
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];