2012-07-19 118 views
1

我試圖將視頻編碼到我的iPhone應用程序中,下面的代碼完美地工作,但唯一的是我寧願視頻不會在用戶自動開始播放時打開頁面。我希望他們能夠按下播放按鈕。下面的代碼位於我的viewcontroller.m文件中。如何讓視頻播放器在使用MPMoviePlayerController時不自動播放

(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

沒關係,我理解了它。我只是在[player prepareToPlay]下加player.shouldAutoplay = NO

0

不要把它放在你的viewDidLoad中。只需創建一個IBAction,將它們連接到觸發按鈕。

相關問題