• 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
                });
            }
        }];
  • 相关阅读:
    如何把textfield或者textview中长按出现的(全选,复制,粘贴)显示成中文
    免费真机调试 -- Xcode7
    Android性能测试工具 Emmagee
    iOS 开发 入门:使用Ad Hoc 进行用户测试
    栈与队列的区别
    iOS中ASI和AFN的区别
    iOS开发之监测网络状态
    xcode设置项目图标玻璃镜效果
    isEqual,isEqualTostring,==三者的区别
    iphone匹配邮箱的正则表达式
  • 原文地址:https://www.cnblogs.com/ZhangShengjie/p/10557183.html
Copyright © 2020-2023  润新知