Objective c MPMoviePlayerController在四秒钟后停止

Objective c MPMoviePlayerController在四秒钟后停止,objective-c,ios,mpmovieplayercontroller,Objective C,Ios,Mpmovieplayercontroller,我正在尝试设置一个非常简单的视频播放器。(iOS 5.1,Xcode 4.3.1) 它在被调用时工作正常,但只播放四秒钟,然后会出现一个黑屏。如果我在播放过程中点击屏幕,它将播放整个序列。如果我停止敲击屏幕四秒钟,就会出现黑屏 我错过了什么 库尔特 编辑版本播放良好 在接口文件中: @property (nonatomic,strong) MPMoviePlayerController *myMovieController; 在.m文件中: -(void)playMedia { NSStri

我正在尝试设置一个非常简单的视频播放器。(iOS 5.1,Xcode 4.3.1)

它在被调用时工作正常,但只播放四秒钟,然后会出现一个黑屏。如果我在播放过程中点击屏幕,它将播放整个序列。如果我停止敲击屏幕四秒钟,就会出现黑屏

我错过了什么

库尔特


编辑版本播放良好

在接口文件中:

@property (nonatomic,strong) MPMoviePlayerController *myMovieController;
在.m文件中:

-(void)playMedia {
NSString *movieFile = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieFile]];

[moviePlayer prepareToPlay];
moviePlayer.view.frame = self.view.bounds;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayer.fullscreen = YES;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

self.myMovieController = moviePlayer;
[self.view addSubview: self.myMovieController.view];

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(playMediaFinished:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:moviePlayer];
[self.myMovieController play];
}

如果你使用ARC,我相信你需要保留外部的电影播放器。我自己刚把它分配到一个新的地方。HTH

解决方案是播放器必须是视图控制器的实例变量或属性。 ie我们必须使用MPMoviePlayerController的实例


@属性(非原子,强)MPMoviePlayerController*myMovieController

我正在使用ARC,但请原谅我的无知。如果我调用[moviePlayer retain],我会收到一条错误消息“ARC禁止发送‘retain’的明确消息”。谢谢你的快速回复,明白了。正如你所说,你分配了一个财产。我会编辑这篇文章。好东西,很高兴它成功了。不知道是否有另一种更聪明的方法来做ARC中的retain,就像你说的,你不能显式地调用retain,但是属性完成了任务。为我工作!谢谢倒过来想,我猜这是有道理的。不管怎样,谢谢
-(void)playMedia {
NSString *movieFile = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieFile]];

[moviePlayer prepareToPlay];
moviePlayer.view.frame = self.view.bounds;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayer.fullscreen = YES;
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

self.myMovieController = moviePlayer;
[self.view addSubview: self.myMovieController.view];

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(playMediaFinished:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:moviePlayer];
[self.myMovieController play];
}