视频没有在iPhone模拟器中显示(但我可以听到来自视频的音频)
问题描述:
我是xcode,界面生成器和iphone模拟器的新手。我试图通过单击按钮(这非常简单)在xcode中播放电影/视频。我正在使用xcode 3.2.4和iphone模拟器4.1。视频没有在iPhone模拟器中显示(但我可以听到来自视频的音频)
当我启动iPhone模拟器并点击按钮启动视频时,音频播放,但视频被隐藏。就好像视频在标签栏后面(这是标签栏应用程序的一部分)。我不知道如何让视频在前面播放。
下面的代码:
-(IBAction)launchVideo2:(id)sender{
NSString *movieFile;
MPMoviePlayerController *moviePlayer;
movieFile = [[NSBundle mainBundle]
pathForResource:@"IGDIs_Video_Picture_Naming_iPhone" ofType:@"mp4"];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath: movieFile]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playMediaFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[moviePlayer play];
}
-(void)playMediaFinished:(NSNotification*)theNotification
{
MPMoviePlayerController *moviePlayer=[theNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
}
任何建议将是巨大的!
答
它看起来并不像你所添加的电影,以便你的主要观点。您需要添加如下内容:
...
[[moviePlayer view] setFrame:[self view] bounds]];
[[self view] addSubview:[moviePlayer view]];
[moviePlayer play];
}
在播放之前。我假设launchVideo2方法位于拥有主视图的UIViewController中。您可能需要更改[self view]
以适合您的代码,以对应您希望电影播放的视图。
答
你有可能不相关的记忆问题有:
- 在你的第一个方法,你不松开播放器,这是一个局部变量。
- 在你的第二种方法中,你释放了玩家,你不拥有。
正确的内存管理(即最佳实践),你可以用伊娃做到这一点。
我不是最大的阅读/理解文档还没有...你有一个使用MPMoviePlayerViewController的代码的例子吗? – Justin 2010-11-04 02:35:37
试一下stackoverflow问题http://stackoverflow.com/questions/4077096/how-can-i-play-a-movie-locally-with-the-mpmovieplayerviewcontroller – 2010-11-04 02:43:54
我从你上面提供的例子中精确地复制了代码并添加了建议的代码: – Justin 2010-11-07 00:35:07