首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS如何在一个视图中播放多个视频

iOS如何在一个视图中播放多个视频
EN

Stack Overflow用户
提问于 2012-11-15 05:07:50
回答 1查看 1.2K关注 0票数 1

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

代码语言:javascript
运行
复制
-(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;
}

但是每当我尝试播放这两个视频时,我播放的第二个视频就会使应用崩溃。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2013-11-10 01:23:03

使用AVPlayerAVPlayerLayer而不是MPMoviePlayerController。看看下面的apple example

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13387330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档