2

我正在尝试使用 MPMoviePlayerController 播放捆绑包中的视频,它显示“使用未声明的标识符 'MPMoviePlayerController'”。我是否需要导入任何库才能使用此类?另外,我想知道如何不全屏播放以及如何选择播放框的大小。

编码:

NSString *url = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
moviePlayer.shouldAutoplay=YES;
CGRect videoRect = CGRectMake(0, 0, 300, 250); 
moviePlayer.view.frame = videoRect;
[self.view  addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
4

1 回答 1

0

您需要导入/包含电影播放器​​:MediaPlayer/MediaPlayer.h

此外,必须将 MediaPlayer.framework 添加到 XCode 项目中的“Frameworks”文件夹中。

不全屏播放:

self.moviePlayer.shouldAutoplay=YES;
CGRect videoRect = CGRectMake(0, 0, 300, 250); // define the player's dimensions in compact mode here its 300 * 250
self.moviePlayer.view.frame = videoRect;
[self.view  addSubview:self.moviePlayer.view];
于 2013-10-25T20:30:54.560 回答