zoukankan      html  css  js  c++  java
  • open file /var/mobile/Media/DCIM 相册中获取到的视频地址使用 报错 视频文件不存在

    从相册中获取到的视频地址 例如  file:///var/mobile/Media/DCIM/100APPLE/IMG_9876.MOV 

    后面再使用的时候报错 视频文件不存在  那是因为在ios10、11 设备上需要在请求一次权限

        PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
        options.networkAccessAllowed = YES;
        options.version = PHVideoRequestOptionsVersionCurrent;
        options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
            
        };
        //相册中获取到的phAsset;
        PHAsset *phAsset; //= self.sset;
        
        [[PHImageManager defaultManager] requestAVAssetForVideo:phAsset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
            if(([asset isKindOfClass:[AVComposition class]] && ((AVComposition *)asset).tracks.count == 2)){
                //slow motion videos. See Here: https://overflow.buffer.com/2016/02/29/slow-motion-video-ios/
                
                //Output URL of the slow motion file.
                NSString *root = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
                NSString *tempDir = [root stringByAppendingString:@"/com.sdk.demo/temp"];
                if (![[NSFileManager defaultManager] fileExistsAtPath:tempDir isDirectory:nil]) {
                    [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:nil];
                }
                NSString *myPathDocs =  [tempDir stringByAppendingPathComponent:[NSString stringWithFormat:@"mergeSlowMoVideo-%d.mov",arc4random() % 1000]];
                NSURL *url = [NSURL fileURLWithPath:myPathDocs];
                //Begin slow mo video export
                AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
                exporter.outputURL = url;
                exporter.outputFileType = AVFileTypeQuickTimeMovie;
                exporter.shouldOptimizeForNetworkUse = YES;
                
                [exporter exportAsynchronouslyWithCompletionHandler:^{
                    dispatch_async(dispatch_get_main_queue(), ^{
                        if (exporter.status == AVAssetExportSessionStatusCompleted) {
                            NSURL *URL = exporter.outputURL;
                            AVURLAsset *asset = [AVURLAsset assetWithURL:URL];
                            dispatch_async(dispatch_get_main_queue(), ^{
    //                            completion(asset, nil);
                                //拿到有权限的asset
                            });
                        }else {
                            dispatch_async(dispatch_get_main_queue(), ^{
    //                            错误
    //                            completion(nil, exporter.error);
                            });
                        }
                    });
                }];
            }else {
                dispatch_async(dispatch_get_main_queue(), ^{
    //                completion(asset, nil);
                    //拿到有权限的asset
                });
            }
        }];
  • 相关阅读:
    redis 内部数据结构 ziplist
    redis 内部数据结构 robj
    redis 内部数据结构 sds
    redis 内部数据结构 dict
    【工具篇 intellij idea】像eclipse的 Ctrl + T 那样查看类的继承结构
    【分享系列】+【提炼总结】一文掌控面试必备的TCP知识
    【搬砖系列】一图搞懂 取余 和 取模 运算
    IOS代理(初级)
    UITableView
    UITextField属性
  • 原文地址:https://www.cnblogs.com/ZhangShengjie/p/10557183.html
Copyright © 2011-2022 走看看