我正在开发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];
}
要补充的事情:
如果我打印网址,我会看到:
file:///var/mobile/Containers/Data/Application/93D7BE2E-2622-4614-9E8B-2DA07593D68D/Documents/2b6f779a63e9d714944f66f01f05a3b437b79f43
这就是我手动添加扩展名
的原因videoUrl = [videoUrl URLByAppendingPathExtension:@"3gp"];
此外,如果我打印播放器项目的状态,它总是打印0 - >未定义
NSLog(@"item status: %ld", playerItem.status);
关于错误在哪里的任何想法?
提前致谢