zoukankan      html  css  js  c++  java
  • iOS沙盒视频缩略图及保存本地

    获取缩略图

    func thumbnailOfVideo(path : String)-> UIImage {
        do {
            let asset = AVURLAsset(url: URL(fileURLWithPath: path), options: nil)
            let imgGenerator = AVAssetImageGenerator(asset: asset)
            imgGenerator.appliesPreferredTrackTransform = true
            let cgImage =  try imgGenerator.copyCGImage(at: CMTimeMakeWithSeconds(1, 24), actualTime: nil)
            let uiImage = UIImage(cgImage: cgImage)
            return uiImage
        } catch {
            return UIImage(named: "default_figure")!
        }
    }
    

    保存到系统相册

    #import <AssetsLibrary/AssetsLibrary.h>
    - (void)saveVideoIntoAlbum {
        NSString *fileDirectory = 
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSArray *fileArray = [fileManager contentsOfDirectoryAtPath:fileDirectory error:nil];
        NSString *filePath = [fileDirectory stringByAppendingPathComponent:[fileArray lastObject]];
        NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
        
        NSLog(@"fileUrl = %@", fileUrl);
        ALAssetsLibrary *assetslibrary = [[ALAssetsLibrary alloc] init];
        
        if ([assetslibrary videoAtPathIsCompatibleWithSavedPhotosAlbum:fileUrl]) {
            [assetslibrary writeVideoAtPathToSavedPhotosAlbum:fileUrl completionBlock:^(NSURL *assetURL, NSError *error) {
                NSLog(@"%@-----%@", assetURL, error);
            }];
        } else {
            
        }
    }
    
  • 相关阅读:
    网站开发感悟
    jQuery之字体大小的设置
    jQuery之load方法
    jQuery之get方法
    MongoVUE的使用
    jQuery之ajax删除
    jQuery之选项卡的实现
    jQuery之简单的表单验证
    jQuery滑动效果实例
    jQuery之下拉框左右选择
  • 原文地址:https://www.cnblogs.com/horo/p/6991229.html
Copyright © 2011-2022 走看看