I am using the below code, for streaming the two videos sequentially. But it is not showing any video in the simulator, its totally blank.
Also how can I seek through these two videos. Like, if one video is of 2 minutes and the second is 3 minutes. Now I need to get the total time of these videos and seek through them. When I slide the slider bar to 4 minutes so the 2nd video should be played from minute 2 to onward.
Is it possible?
- (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];
}
Can anyone tell me that what is the error in my code?