2010-09-13 107 views
1

我试图从iPhone设备上的服务器上播放视频。我使用下面的方法来实现,但是,它只能在模拟器中使用;和我的iPhone 4上。它不适用于iPhone 3G?MPMoviePlayerViewController意外退出

如果我在iPhone 3G上调用此方法,它会打开视频模式屏幕,开始加载视频,然后突然关闭模式屏幕。在控制台中不显示错误。

iPhone 3G已安装4.0版本。我的iPhone 4有4.1版本。

有没有其他人经历过这个?

-(IBAction)playMedia{ 

NSString* url = [self.data objectForKey:@"url"];  

//initialize the movie player 
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]]; 

//show a background image while the user waits 
moviePlayerViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 


//show the movie 
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController]; 

[moviePlayerViewController release]; 

} 
+0

您是否可以通过iOS 4获得iPhone 3G以通过其他应用播放远程视频?一些人(包括我自己)在3G设备上运行iOS 4时遇到了很多问题。如果您在其他应用中遇到稳定性问题,请尝试重新启动设备,然后重试? – pix0r 2010-09-13 22:26:03

回答

0

我会做上面的有点不同:

-(IBAction)playMedia{ 

NSString* url = [self.data objectForKey:@"url"];  

//initialize the movie player 

MPMoviePlayerViewController *tmpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]]; 
self.moviePlayerViewController = tmpPlayer; 

//show a background image while the user waits 
UIColor *tmpColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background.png"]]; 
self.moviePlayerViewController.view.backgroundColor = tmpColor; 

self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 

//show the movie 
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController]; 

[tmpPlayer release]; 
[tmpColor release]; 
} 
+0

嗨,这段代码适用于Xcode和iPhone3GS中的iOS5 .. – 2012-06-07 06:38:29

1

确定我有视频,两个iPhone 4和iPhone 3G的工作。基本上问题是文件格式。我正在播放.mov文件。当我将格式更改为.mp4时,它现在可以在两台设备上使用。代码没有变化。

希望这可以帮助他人解决同样的问题。

+0

我用Quicktime将它改为.m4v文件,它运行良好。在QT10中打开视频,点击文件 - >另存为,然后选择iPhone作为输出。然后更改代码以反映扩展更改。像魅力一样工作! – 2011-05-12 13:24:10