2013-03-27 58 views
2

我想使用MPMoviePlayerController在我的iPad应用程序中播放视频。我的问题是,该播放器只显示“加载”,不播放视频。下面是我的代码使用方法:MPMoviePlayerController不加载电影

- (void)playMovieFile:(NSString *)fileName 
{ 
    NSString *filePath=[[NSBundle mainBundle] pathForResource:fileName ofType:@"mov"]; 
    NSURL *fileUrl=[NSURL fileURLWithPath:filePath]; 

    self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:fileUrl]; 
    [self.moviePlayer.view setFrame:self.view.frame]; 

    [self.view addSubview:self.moviePlayer.view]; 
    [self.moviePlayer prepareToPlay]; 
    [self.moviePlayer play]; 
} 

我也尝试使用MPMoviePlayerViewController,但神志清醒success.Also,什么电影类型做的MPMoviePlayerController播放?这是因为电影的大小吗?它是263 MB。

回答

5

iPhone支持的电影格式为.mov, .m4v, mp4 or 3gp

The video technologies in iOS support the playback of movie files with the .mov, .mp4, .m4v, and .3gp filename extensions and using the following compression standards:

如果您在播放电影与上述的扩展即可。声明你的MPMoivePlayer作为类的类型属性在.h

@property(strong,nonatomic)MPMoviePlayerController *moviePlayer; 

.m

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"mov"]; 

NSURL *fileUrl=[NSURL fileURLWithPath:filePath]; 

self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:fileUrl]; 
[self.moviePlayer.view setFrame:CGRectMake(x,y,width,height)]; 

[self.view addSubview:self.moviePlayer.view]; 
[self.moviePlayer prepareToPlay]; 
[self.moviePlayer play]; 
+0

现在,我已经试过其他的.mov影片,但它不会再次加载。另外,还有其他框架可以播放电影吗? – 2013-03-27 11:03:04

+1

确保你为电影提供了正确的路径,并且如果你正在播放.mov,那么它应该是.mov类型。另外尝试'[moviePlayerController prepareToPlay];' – nsgulliver 2013-03-27 11:06:42

+0

检查我更新的答案 – nsgulliver 2013-03-27 11:12:59

相关问题