如何在使用MPMoviePlayerController时让视频播放器不自动播放

时间:2012-07-19 15:11:42

标签: iphone video mpmovieplayercontroller xcode4.3

我正在尝试将视频编码到我的iPhone应用程序中,下面的代码运行完美,但唯一的一点是我宁愿视频在用户打开页面时不会自动开始播放。我希望他们能够按下播放按钮。下面的代码位于我的viewcontroller.m文件中。

(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];
}

2 个答案:

答案 0 :(得分:4)

没关系,我明白了。我刚刚在[player prepareToPlay]

下添加了player.shouldAutoplay = NO

答案 1 :(得分:0)

不要将它放在viewDidLoad中。只需创建一个IBAction,然后将它链接到触发按钮。

相关问题