Play multiple videos

♀尐吖头ヾ 提交于 2019-12-02 10:44:30

问题


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


回答1:


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.




回答2:


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:


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 !



来源:https://stackoverflow.com/questions/11082206/play-multiple-videos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!