1

我想知道如何在一页中播放多个视频,比如你有两个按钮,当你按下一个时,它会播放一个视频,当你按下另一个时,它会播放另一个。到目前为止我有这个代码:

-(void)WelcomeVideo1
{
    NSURL *url31 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"DirectorsWelcome" ofType:@"mp4"]];
    welcomePlayer1 =  [[MPMoviePlayerController alloc]
                      initWithContentURL:url31];

    welcomePlayer1.controlStyle = MPMovieControlStyleDefault;
   welcomePlayer1.shouldAutoplay = YES;
    [self.view addSubview:welcomePlayer1.view];
    [welcomePlayer1 setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{
    [welcomePlayer1.view removeFromSuperview];
    welcomePlayer1 = nil;
}

- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
      [welcomePlayer1 stop];
    [welcomePlayer1.view removeFromSuperview];
   welcomePlayer1 = nil;
}


-(void)storyVideo1
{
    NSURL *url4 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                          pathForResource:@"OurStory" ofType:@"mp4"]];
    storyPlayer1 =  [[MPMoviePlayerController alloc]
                       initWithContentURL:url4];

    storyPlayer1.controlStyle = MPMovieControlStyleDefault;
    storyPlayer1.shouldAutoplay = YES;
    [self.view addSubview:storyPlayer1.view];
    [storyPlayer1 setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish2:(NSNotification *)aNotification{
    [storyPlayer1.view removeFromSuperview];
    storyPlayer1 = nil;
}

- (void)moviePlayerWillExitFullscreen2:(NSNotification*) aNotification {
    [storyPlayer1 stop];
    [storyPlayer1.view removeFromSuperview];
    storyPlayer1 = nil;
}

但是每当我尝试播放这两个视频时,我播放的第二个视频都会使应用程序崩溃。有任何想法吗?

4

1 回答 1

0

使用AVPlayerandAVPlayerLayer而不是MPMoviePlayerController. 看看下面的苹果例子

于 2013-11-09T17:23:03.073 回答