我使用Photo框架在collectionview中显示了所有图库的视频。我从PHCachingImageManager(PHAsset lib)中提取了视频网址,如下所示:
console.log
因为我必须上传所选视频,所以我将其转换为nsdata,如下所示:
[imageManager requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *vidInfo) {
// Use the AVAsset avAsset
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
NSURL *vUrl=[self urlOfCurrentlyPlayingInPlayer:videoPlayer];
NSString *url=[NSString stringWithFormat:@"%@",vUrl];
if (url.length>0) {
[videoInfo addObject:url];
}
}];
获取以下网址:NSData* data = [NSData dataWithContentsOfFile:selectedFileUrl options:0 error:&error];
但我总是将数据设为null。
我在这里做错了什么?请帮忙!
谢谢!!!
答案 0 :(得分:0)
检查一下:
NSData* data = [NSData dataWithContentsOfFile::[NSURL URLWithString: selectedFileUrl] options:nil error:&error];
答案 1 :(得分:0)
尝试使用它
[imageManager requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset *avAsset, AVAudioMix *audioMix, NSDictionary *vidInfo) {
// Use the AVAsset avAsset
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
NSURL *vUrl=[self urlOfCurrentlyPlayingInPlayer:videoPlayer];
if (vUrl) {
[videoInfo addObject:vUrl];
}
}];
现在您可以使用以下内容获取数据:NSData *videoData = [NSData dataWithContentsOfURL:videoURL];