Alassetslibrary Getting videos from albums

Source: Internet
Author: User

Take video

-(void) Getallvideo

{

Library = [[Alassetslibrary alloc] init];

Monitoring is available

Alassetslibraryaccessfailureblock Failureblock =

^ (Nserror *myerror)

{

NSLog (@ "album Access failed =%@", [Myerror localizeddescription]);

if ([Myerror.localizeddescription rangeofstring:@ "Global denied access"].location!=nsnotfound) {

NSLog (@ "Unable to access the album.) set the location services as set to open.");

}else{

NSLog (@ "album Access failed.");

}

UI hints that are not allowed to be accessed

[Self createnotallowview];

return;

};

Mutablearray =[[nsmutablearray Alloc]init];

Alassetslibrarygroupsenumerationresultsblock

Librarygroupsenumeration = ^ (alassetsgroup* group,bool* stop) {

if (group! = nil)

{

Take video only

[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];

}

Write Local

-(void) Handlewrittenfile: (alasset*) Videoasset

{

if (!videoasset) {

NSLog (@ "nil");

Return

}

Write Local Path

NSString *filename = [self getvideomergefilepathstring];

Alassetrepresentation *represent = [Videoasset defaultrepresentation];

Nsuinteger size = [represent size];

Open 65636-size memory for one read and write

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;

}

Alassetslibrary Getting videos from albums

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.