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