2011-10-23 26 views
0

當我的應用程序加載時,我製作了一個視頻播放,但即使您播放了「完成」,播放後也不會退出。我究竟做錯了什麼?Iphone:啓動時播放的視頻不會退出

- (void)viewDidLoad { 
NSBundle *bundle=[NSBundle mainBundle]; 
NSString *moviePath = [bundle pathForResource:@"Video Logo Final" ofType:@"mp4"]; 
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain]; 
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; 
theMovie.scalingMode = MPMovieScalingModeAspectFill; 
theMovie.view.frame = CGRectMake(0.0, 0.0, 320.0, 480.0); 
[self.view addSubview:theMovie.view]; 
[theMovie play]; 
[super viewDidLoad]; } 

而且,我做了一個嘗試把相同的代碼在「應用程序didFinishLaunchingWithOptions」但我得到的警告「[self.view addSubview:theMovie.view]。」 Ay的想法?

p.s.正如你可能猜到我對編程非常陌生,任何幫助都會非常感謝......

+0

什麼是iOS版本? –

+0

,你可以在這裏閱讀教程:http://iphoneincubator.com/blog/audio-video/play-video-with-mpmovieplayercontroller-in-ios-3-0-and-3-24-0 –

+0

ios 5 xcode 4.2 –

回答

0

基本上你需要註冊一個通知。

我做到這一點的方法是:但是,應該

// Register for the playback finished notification 
[[NSNotificationCenter defaultCenter] addObserver: self 
    selector: @selector(myMovieFinishedCallback:) 
    name: MPMoviePlayerPlaybackDidFinishNotification 
    object: theMovie]; 

更改參數,以適應您的應用程序。

這是documentation for the MPMoviePlayerPlaybackDidFinishNotification。另外,如果它在播放後不是「退出」(即使點擊「完成」按鈕時),聽起來好像需要從最初添加的視圖中刪除theMovie MPMoviePlayerController和相關視圖。