동일한 비디오를 재생하기위한 두 가지 다른보기가 있습니다. 비디오가 실행되는 동안 두 개의보기간에 여러 번 전환하는 응용 프로그램을 만들고 있습니다.하나의 비디오로 두 개의 AVPlayers로드하기
NSURL *url = [NSURL URLWithString:@"http://[URL TO VIDEO HERE]"];
AVURLAsset *avasset = [[AVURLAsset alloc] initWithURL:url options:nil];
AVPlayerItem *item = [[AVPlayerItem alloc] initWithAsset:avasset];
player = [[AVPlayer alloc] initWithPlayerItem:item];
playerLayer = [[AVPlayerLayer playerLayerWithPlayer:player] retain];
CGSize size = self.bounds.size;
float x = size.width/2.0-202.0;
float y = size.height/2.0 - 100;
//[player play];
playerLayer.frame = CGRectMake(x, y, 404, 200);
playerLayer.backgroundColor = [UIColor blackColor].CGColor;
[self.layer addSublayer:playerLayer];
NSString *tracksKey = @"tracks";
[avasset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
^{
dispatch_async(dispatch_get_main_queue(),
^{
NSError *error = nil;
AVKeyValueStatus status = [avasset statusOfValueForKey:tracksKey error:&error];
if (status == AVKeyValueStatusLoaded) {
//videoInitialized = YES;
[player play];
}
else {
// You should deal with the error appropriately.
NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
}
});
}];
을 내 두 번째보기에서 나는 두보기에 비디오가 동기화되어 있도록 dispatch_get_main_queue에서 비디오를로드 할 다음과 같이
나는 현재 비디오와 함께 첫 번째보기를로드합니다.
첫 번째보기의 비디오 데이터를 두 번째보기로로드 할 때 누군가가 나를 도울 수 있기를 바랬습니다.
제 대답을 올바른 것으로 검토하십시오. 감사합니다. – Nikita