2013-03-27 102 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

相關問題