我正在处理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"];
此外,如果我打印player项的状态,它总是打印0 ->未定义。
NSLog(@"item status: %ld", playerItem.status);
对错误在哪里有什么想法吗?
提前感谢
发布于 2017-11-23 12:33:00
https://stackoverflow.com/questions/47455084
复制相似问题