视频没有在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]; 
} 

任何建议将是巨大的!

+0

我不是最大的阅读/理解文档还没有...你有一个使用MPMoviePlayerViewController的代码的例子吗? – Justin 2010-11-04 02:35:37

+1

试一下*问题http://*.com/questions/4077096/how-can-i-play-a-movie-locally-with-the-mpmovieplayerviewcontroller – 2010-11-04 02:43:54

+0

我从你上面提供的例子中精确地复制了代码并添加了建议的代码: – Justin 2010-11-07 00:35:07

它看起来并不像你所添加的电影,以便你的主要观点。您需要添加如下内容:

... 
    [[moviePlayer view] setFrame:[self view] bounds]]; 
    [[self view] addSubview:[moviePlayer view]]; 
    [moviePlayer play]; 
} 

在播放之前。我假设launchVideo2方法位于拥有主视图的UIViewController中。您可能需要更改[self view]以适合您的代码,以对应您希望电影播放的视图。

根据我的经验,视频不会显示在SIM卡中。但是,音频会。 (这是一个改进,因为以前都不会玩。)

尝试在设备上运行应用程序。如果视频不在那里显示,请在这里发帖,我们将解决问题。

+0

我在设备上试过了,它没有工作... – Justin 2010-11-04 02:25:11

+0

看起来像你缺少[self presentMoviePlayerViewControllerAnimated:moviePlayer]; (见亚伦桑德斯评论) – joshpaul 2010-11-04 03:48:51

你有可能不相关的记忆问题有:

  • 在你的第一个方法,你不松开播放器,这是一个局部变量。
  • 在你的第二种方法中,你释放了玩家,你不拥有。

正确的内存管理(即最佳实践),你可以用伊娃做到这一点。