一千萬個為什麽

搜索

我有兩個mpmovieplayercontrollers和兩個單獨的子視圖,他們使用...除了一次只播放一個視頻

我想在兩個獨立的子視圖中同時播放這兩部電影。他們都訪問不同的媒體。

這是在具有超視圖的ipad上,並且在xib上彼此相鄰的兩個小視圖320x240。

-(IBAction)playLeft:(id)sender{
if ([self.playerRight playbackState] == MPMoviePlaybackStatePlaying);
[self.playerRight stop];

[self.playerLeft play];
}

-(IBAction)playRight:(id)sender{
if ([self.playerLeft playbackState] == MPMoviePlaybackStatePlaying);
[self.playerLeft stop];

[self.playerRight play];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

self.playerLeft = [[MPMoviePlayerController alloc] init];
self.playerLeft.contentURL = [self movieURL];

NSLog(@"self.playerLeft %@", self.playerLeft);


self.playerRight = [[MPMoviePlayerController alloc] init];
self.playerRight.contentURL = [self movieURL2];

NSLog(@"self.playerRight %@", self.playerRight);



// START_HIGHLIGHT
self.playerLeft.view.frame = self.leftView.bounds;
self.playerLeft.view.autoresizingMask = 
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;

self.playerRight.view.frame = self.rightView.bounds;
self.playerRight.view.autoresizingMask = 
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;

[self.rightView addSubview:playerRight.view];
[self.leftView addSubview:playerLeft.view];


//[self.playerRight play];

//[self.playerLeft play];


//[self clickedOpenMovie:nil];

}

-(NSURL *)movieURL
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = 
[bundle 
      pathForResource:@"720p5994-prores-hq_iPhone_320x240 two" 
 ofType:@"m4v"];
//NSString *moviePath = [NSString stringWithFormat:@"http://localhost:1935/live/aStream/playlist.m3u8"];

if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
//return [NSURL URLWithString:moviePath];

} else {
return nil;
}
}

-(NSURL *)movieURL2
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = 
[bundle 
pathForResource:@"720p5994-prores-hq_iPhone_320x240" 
ofType:@"m4v"];
if (moviePath) {
return [NSURL fileURLWithPath:moviePath];
} else {
return nil;
}
}

最佳答案

所以問題是在後臺的某個地方MPMoviePlayerController響應通知並在另一個MPMoviewPlayerController廣播它將開始時自動關閉。因此,不能同時播放多個MPMoviePlayerControllers。

你可以通過打印出MPMoviePlayerPlaybackStateDidChangeNotification來看到這一點

轉載註明原文: 我有兩個mpmovieplayercontrollers和兩個單獨的子視圖,他們使用...除了一次只播放一個視頻