1

我正在尝试从 iPhone 设备上的服务器上播放视频。我正在使用以下方法来执行此操作,但是,它仅适用于模拟器;在我的 iPhone 4 上。它在 iPhone 3G 上不起作用?

如果我在 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];

}
4

2 回答 2

1

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

希望这可以帮助其他有同样问题的人。

于 2010-09-15T00:59:38.550 回答
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];
}
于 2010-09-13T23:11:29.180 回答