1

我正在尝试将视频编码到我的 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];
}
4

2 回答 2

4

没关系,我想通了。我刚刚[player prepareToPlay]在下面添加player.shouldAutoplay = NO

于 2012-07-19T17:49:50.740 回答
0

不要把它放在你的 viewDidLoad 中。只需创建一个 IBAction 他们将其链接到您的触发按钮。

于 2013-05-31T11:47:53.903 回答