我正在参加在线类(class),他们使用 MPMoviePlayerController 使用过时的代码,我需要具体说明如何将其更改为使其正常工作。我正在制作的应用程序有一个表格 View Controller ,其中有一个包含消息的收件箱。可以发送短视频文件,当您点击有视频消息的行时,我需要播放视频文件。免费试用版即将到期,所以我需要帮助。
这是我的头文件中需要更改的内容:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
这是我的实现文件中的 viewDidLoad 方法中需要更改的内容:
self.moviePlayer = [[MPMoviePlayerController alloc] init];
这也是实现文件中需要改变的地方。我通过 Parse.com 通过后端获取视频,这就是 PFFile 的含义:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
self.moviePlayer.contentURL = fileUrl;
[self.moviePlayer prepareToPlay];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer setFullscreen:YES animated:YES];
}
最佳答案
在头文件中:
@property(nonatomic,strong)AVPlayer *avPlayer;
在实现文件中的 viewDidLoad 方法中
self.avPlayer = [[AVPlayer alloc] init];
在实现 UITableView 方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
NSURL *fileURL = [NSURL fileURLWithPath:videoFile.url];
self.avPlayer = [AVPlayer playerWithURL:fileURL];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
layer.frame = CGRectMake(0, 0, width, height);
[self.view.layer addSublayer: layer];
[self.avPlayer play];
}
希望它会帮助你:)
关于ios - 使用 MPMoviePlayerController 将代码更改为 AVPlayer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33450623/