我正在使用下面的代码,按顺序流式传输两个视频。但它没有在模拟器中显示任何视频,它完全是空白的。
另外我怎么能通过这两个视频寻找。比如,如果一个视频是 2 分钟,第二个是 3 分钟。现在我需要获取这些视频的总时间并通过它们进行搜索。当我将滑块滑动到 4 分钟时,第二个视频应该从第 2 分钟开始播放。
可能吗?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSURL *url1 = [NSURL URLWithString:@"http://www.tools4movies.com/dvd_catalyst_profile_samples/Harold%20Kumar%203%20Christmas%20bionic.mp4"];
NSURL *url2 = [NSURL URLWithString:@"http://www.tools4movies.com/dvd_catalyst_profile_samples/Harold%20Kumar%203%20Christmas%20tablet.mp4"];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVMutableComposition *composition = [[AVMutableComposition alloc] init];
asset1 = [[AVURLAsset alloc] initWithURL:url1 options:options];
AVURLAsset * asset2 = [[AVURLAsset alloc]initWithURL:url2 options:options];
CMTime insertionPoint = kCMTimeZero;
NSError * error = nil;
composition = [AVMutableComposition composition];
if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset1.duration)
ofAsset:asset1
atTime:insertionPoint
error:&error])
{
NSLog(@"error: %@",error);
}
insertionPoint = CMTimeAdd(insertionPoint, asset1.duration);
if (![composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset2.duration)
ofAsset:asset2
atTime:insertionPoint
error:&error])
{
NSLog(@"error: %@",error);
}
AVPlayerItem * item = [[AVPlayerItem alloc] initWithAsset:composition];
player = [AVPlayer playerWithPlayerItem:item];
AVPlayerLayer * layer = [AVPlayerLayer playerLayerWithPlayer:player];
[layer setFrame:CGRectMake(0, 0, 320, 480)];
[[[self view] layer] addSublayer:layer];
[player play];
}
谁能告诉我我的代码有什么错误?