iOS沙盒视频缩略图及保存本地代码
程序员文章站
2023-12-22 08:40:46
本文实例为大家分享了ios沙盒视频缩略图及保存本地的具体代码,供大家参考,具体内容如下
获取缩略图
func thumbnailofvideo(path : s...
本文实例为大家分享了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 { } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读