Play multiple videos

2020-04-22 06:39发布

I'm actually using the MPMoviePlayerController for play video in my iPad app.

Actually, I can easly play 1 video but I'm trying to play in the same time 2 video, here is my code :

// Look for the video in the main bundle
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];

NSString *urlStr2 = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
NSURL *url2 = [NSURL fileURLWithPath:urlStr2];

videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:videoPlayer.view];
videoPlayer.view.frame = CGRectMake(0, 0,200, 200); 

videoPlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:url2];
[self.view addSubview:videoPlayer2.view];
videoPlayer2.view.frame = CGRectMake(0, 300,200, 200);

[videoPlayer2 play];
NSLog(@"Video 1 playing");

[videoPlayer play];
NSLog(@"Video 2 playing");

The first video is correctly launched but not the second. (and btw the second video does not lauch after the first finished)

Here is my output :

2012-06-18 13:47:23.015 testMosaique[2498:11f03] Video 1 playing

2012-06-18 13:47:23.016 testMosaique[2498:11f03] Video 2 playing

Is there a way while using MPMoviePlayerController to play 2 or more videos at the same time?

Thank's

3条回答
该账号已被封号
2楼-- · 2020-04-22 07:19

As Safecase mentioned, MPMovieplayerController will only allow one video to be played at a time. But here is an example to play two simultaneously with the use of AVFoundation:

http://www.sdkboy.com/?p=66

Hope this helps!

查看更多
贪生不怕死
3楼-- · 2020-04-22 07:29

If you want to play more than one video at the same time you have to use AVPlayer frameworks. MPMovie only allowed you play one video at a time.

See AVPlayer documentation.

查看更多
放我归山
4楼-- · 2020-04-22 07:31

What I did is display 4 videos using AVPlayer, but those video are made from 4 another video (I create each videos with AVFoundation). Si I'm able the display thousand and thousand videos in only 4 players, pretty good performances when you play the videos !

查看更多
登录 后发表回答