如何在使用MPMoviePlayerController时使视频播放器不自动播放 [英] How to get video player to NOT auto play while using MPMoviePlayerController

查看:65
本文介绍了如何在使用MPMoviePlayerController时使视频播放器不自动播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将视频编码到我的iPhone应用程序中,下面的代码可以正常工作,但是唯一的事情是,我宁愿用户打开页面时视频也不会自动开始播放.我希望他们能够按播放"按钮.下面的代码位于我的viewcontroller.m文件中.

I'm trying to code a video into my iPhone app and the code below works perfectly but the only thing is that I rather the video not automatically start playing when the user opens the page. I want them to be able to push the play button. The code below is located in my viewcontroller.m file.

(void)viewDidLoad
{
NSString *url = [[NSBundle mainBundle] pathForResource:@"77860_00_01_MM02_welcome" 
ofType:@"mov"];
player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
 addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player];

player.view.frame = CGRectMake(10, 235, 150, 125);
[self.view addSubview:player.view];

[player play];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *moviePlayer = [aNotification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer.view removeFromSuperview];
[player play];
}

推荐答案

没关系,我知道了.我只是在player.shouldAutoplay = NO

Never mind, I figured it out. I just added [player prepareToPlay] under player.shouldAutoplay = NO

这篇关于如何在使用MPMoviePlayerController时使视频播放器不自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆