我尝试使用AVPlayerViewController
播放 mp4 视频。我使用“http url”,它可以播放,但是当我使用时fileUrl
,它不起作用......
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"mp4ForDownloadTest" ofType:@"mp4"];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO];
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc] init];
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
playerVC.player = player;
[self presentViewController:playerVC animated:YES completion:^{
[player play];
}];
}