代码之家  ›  专栏  ›  技术社区  ›  theprojectabot

我有两个mpmovieplayercontroller和两个他们使用的独立子视图…除了一次只能播放一个视频

  •  0
  • theprojectabot  · 技术社区  · 16 年前

    我想让两部电影同时在两个单独的子视图中播放。他们都在访问不同的媒体。

    这是在一个ipad上,有一个超级视图和两个320x240的小视图,在xib上互相连接。

    -(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;
    }
    }
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   theprojectabot    16 年前

    所以问题是,在后台的某个地方,如果另一个mpmoviewplayercontroller广播它将要开始的内容,mpmoviewplayercontroller会响应通知并自动关闭。因此,不能同时播放多个mpmovieplayercontroller。

    您可以通过打印mpmovieplayerplaybackstatedidchangenotification看到这一点。

    推荐文章