2011-10-23 25 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和相关视图。