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