我正在开发iOS应用程序。在那里,我想播放一段存储在本地文件系统中的视频。所以我用的是AVPlayer。但是当我试着播放视频时,我总是看到播放符号交叉。
这是我的代码:
- (void)playVideo:(NSURL *)videoUrl onView:(UIView *)view{
videoUrl = [videoUrl URLByAppendingPathExtension:@"3gp"];
NSLog(@"file url: %@", videoUrl);
AVURLAsset *asset = [AVURLAsset assetWithURL:videoUrl];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = playVideo;
playerViewController.player.volume = 0;
playerViewController.view.frame = view.bounds;
[self.viewController addChildViewController: playerViewController];
[self.viewController.view addSubview:playerViewController.view];
[playVideo play];
}
需要补充的几点:
如果我打印url,我会看到:
file:///var/mobile/Containers/Data/Application/93D7BE2E-2622-4614-9E8B-2DA07593D68D/Documents/2b6f779a63e9d714944f66f01f05a3b437b79f43
这就是为什么我要手动添加扩展名
videoUrl = [videoUrl URLByAppendingPathExtension:@"3gp"];
如果我打印玩家物品的状态,它总是打印0->未定义
NSLog(@"item status: %ld", playerItem.status);
你知道错误在哪里吗?
提前感谢