MPMoviePlayerController不加载电影

时间:2013-03-27 10:47:57

标签: ios objective-c ipad mpmovieplayercontroller

我想使用MPMoviePlayerController在我的iPad应用中播放视频。我的问题是,该播放器只显示“正在加载”而不播放视频。这是我使用的代码:

- (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,但是成功了。还有,MPMoviePlayerController会播放哪些电影类型?可以因为电影的大小吗?它是263 MB。

1 个答案:

答案 0 :(得分: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:

如果您使用上述扩展名播放电影,那么。在您的.h

中将MPMoivePlayer声明为类类型属性
@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];