How to get video player to NOT auto play while using MPMoviePlayerController

假如想象 提交于 2019-12-11 05:28:22

问题


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

回答1:


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




回答2:


Don't put it in your viewDidLoad. Just create an IBAction them link it up to your trigger button.



来源:https://stackoverflow.com/questions/11563840/how-to-get-video-player-to-not-auto-play-while-using-mpmovieplayercontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!