我正在使用自定义图像选择器来选择时间流逝,我想获取所选择的时间流逝的 url,这样我就可以播放时间流逝了。
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
NSURL *url = [NSURL URLWithString: assetURLgoesHere];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[videoPlayer play];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
这是我目前拥有的,但我需要获取资产的 url。
我通常使用 swift,但这个自定义图像选择器是用 Objective-c 编写的。所以我有点客观-c 菜鸟
更新代码
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
- (PHImageRequestID)requestAVAssetForVideo:(PHAsset *)asset options:(PHVideoRequestOptions *)options resultHandler:(void (^)(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info))resultHandler
NSURL *url = [NSURL URLWithString: asset];
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:avAsset];
AVPlayer *videoPlayer = [AVPlayer playerWithPlayerItem:playerItem];
[videoPlayer play];
}
[self dismissViewControllerAnimated:YES completion:NULL];
}