zoukankan      html  css  js  c++  java
  • ALAssetsLibrary从相册 获取视频

    /// 取视频

    -(void)getAllVideo

    {

        library = [[ALAssetsLibrary alloc] init];

        //监测是否可用

        ALAssetsLibraryAccessFailureBlock failureblock =

        ^(NSError *myerror)

        {

            NSLog(@"相册访问失败 =%@", [myerror localizedDescription]);

            if ([myerror.localizedDescription rangeOfString:@"Global denied access"].location!=NSNotFound) {

                NSLog(@"无法访问相册.请在'设置->定位服务'设置为打开状态.");

            }else{

                NSLog(@"相册访问失败.");

            }

       /// 不允许访问的UI提示

            [self createNotAllowView];

            return ;

        };

        mutableArray =[[NSMutableArray alloc]init];

        ALAssetsLibraryGroupsEnumerationResultsBlock

        libraryGroupsEnumeration = ^(ALAssetsGroup* group,BOOL* stop){

            if (group != nil)

            {

        /// 只取视频

                [group setAssetsFilter:[ALAssetsFilter allVideos]];

                [group enumerateAssetsWithOptions:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {

                    if (result) {

                        [mutableArray addObject:result];

                    }

                }];

            }

            else

            {

                NSLog(@"%ld",mutableArray.count);

                [_collectionView reloadData];

            }

        };

        [library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos

                                                             usingBlock:libraryGroupsEnumeration

                                                           failureBlock:failureblock];

    }

    /// 写入本地

    -(void)handleWrittenFile:(ALAsset*) videoAsset

    {

        if (!videoAsset) {

            NSLog(@"nil");

            return;

        }

      /// 写入本地路径 

        NSString *fileName = [self getVideoMergeFilePathString];

        ALAssetRepresentation *represent = [videoAsset defaultRepresentation];

        NSUInteger size = [represent size];

      /// 开辟65636大小的内存 一次读取和写入 

        const int bufferSize = 65636;

        NSLog(@"written to : %@", fileName);

        FILE *fileOpen = fopen([fileName cStringUsingEncoding:1], "wb+");

        if (fileOpen == NULL) {

            return;

        }

        Byte *buffer =(Byte*)malloc(bufferSize);

        NSUInteger read =0, offset = 0;

        NSError *error;

        if (size != 0) {

            do {

                read = [represent getBytes:buffer

                          fromOffset:offset

                              length:bufferSize

                               error:&error];

                fwrite(buffer, sizeof(char), read, fileOpen);

                offset += read;

            } while (read != 0);

        }

        free(buffer);

        buffer = NULL;

        fclose(fileOpen);

        fileOpen= NULL;

    }

  • 相关阅读:
    【转】 史上最详尽的平衡树(splay)讲解与模板(非指针版spaly)
    HihoCoder1325 : 平衡树·Treap(附STL版本)
    HihoCOder1323 : 回文字符串(区间DP)
    从分布式一致性算法到区块链共识机制
    Nacos Committer 张龙:Nacos Sync 的设计原理和规划
    MaxCompute Studio使用心得系列7——作业对比
    阿里云MaxCompute 2019-4月刊
    DDoS攻击新趋势:海量移动设备成为新一代肉鸡
    胡喜:从 BASIC 到 basic ,蚂蚁金服技术要解决两个基本的计算问题
    阿里开发者招聘节 | 面试题14:如何实现两金额数据相加(最多小数点两位)
  • 原文地址:https://www.cnblogs.com/xia0huihui/p/5430782.html
Copyright © 2011-2022 走看看