retrieve video format using AssetLibrary and display on uilabel - iphone

I would like to know how to retrieve video format using AssetLibrary and display on uilabel? i read on forum to use ALAssetPropertyRepresentations but im just lost. some help please?

I'm not sure what you mean by "format", but this code will display the video's UTI (basically, file type) and any metadata.
ALAssetsGroupEnumerationResultsBlock assetEnumerator = ^(ALAsset *asset, NSUInteger index, BOOL *stop) {
if(asset != nil) {
ALAssetRepresentation* representation = [asset defaultRepresentation];
NSLog(#"UTI = %#", [representation UTI]);
NSLog(#"Metadata = %#", [representation metadata]);
}
};
ALAssetsLibraryGroupsEnumerationResultsBlock assetGroupEnumerator = ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group setAssetsFilter:[ALAssetsFilter allVideos]];
[group enumerateAssetsUsingBlock:assetEnumerator];
}
};
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {
NSLog(#"A problem occured. %#", error);
}];
[library release];
(Code modified from here.)
If you already have your asset, the code to update the label looks like this:
myLabel.text = [[myAsset defaultRepresentation] UTI];

Related

How to make an UI as it is in the screenshot?

I am working on an iPhone application. I have an option to select existing photos from Album. There should be an option for quick access for some images as it is in iMessage. Please check the attached screenshot for more information.
Any idea ?
I found the solution for my question:
First I am reading maximum 20 recent images from Photo Album using below code. Then I am adding all the images into UIScrollView. The last one is More. If user click on it, it will show iPhone default "UIImagePickerController" to choose other images.
If anybody found a better solution, please post it.
Code
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *asset, NSUInteger index, BOOL *innerStop) {
if (asset) {
if ([self.stackForImages count] >= 20) {
// Stop the enumerations
*stop = YES;
*innerStop = YES;
[self initializeMedia];
} else {
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSMutableDictionary *workingDictionary = [[NSMutableDictionary alloc] init];
[workingDictionary setObject:[asset valueForProperty:ALAssetPropertyType] forKey:UIImagePickerControllerMediaType];
[workingDictionary setObject:[UIImage imageWithCGImage:[asset thumbnail]] forKey:UIImagePickerControllerEditedImage];
[workingDictionary setObject:[UIImage imageWithCGImage:[representation fullScreenImage]] forKey:UIImagePickerControllerOriginalImage];
[workingDictionary setObject:[[asset valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]] forKey:UIImagePickerControllerReferenceURL];
[self.stackForImages addObject:workingDictionary];
}
}
}];
if ([self.stackForImages count] > 0) {
[self initializeMedia];
}
} failureBlock: ^(NSError *error) {
}];

AVCapture pause screen after take photo

I have used demo example of avcapture ,i wanna display image in imagview in viewcontroller after take photo i have use code
{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
NSInteger numberOfAssets = [group numberOfAssets];
if (numberOfAssets > 0) {
NSInteger lastIndex = numberOfAssets-1;
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:lastIndex] options:0 usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
UIImage *thumbnail = [UIImage imageWithCGImage:[result thumbnail]];
if (thumbnail && thumbnail.size.width > 0) {
imagviewlastimage.image = thumbnail;
*stop = YES;
}
}];
}
} failureBlock:^(NSError *error) {
NSLog(#"error: %#", error);
}];
to get last image from photo library but i am gatting second last image
and to redirect viewController after pick image i have wrote in
captureManagerStillImageCaptured:(AVCamCaptureManager *)captureManager delegate
ViewController *temp=[[ViewController alloc]init];
temp.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:temp animated:YES];
use as this , how to resolve this ? ya pause screen after take photo

iPhone: How to get Video file binary when using ALAssetsLibrary enumeration?

I am trying to access iPhone's photo album gallery through ALAssetsLibrary. I am successful accessing the photo album and get the asset URL of each images on the device. My testing is, after getting all the images, uploading to my web server is also working well.
I am also trying to get the video file and do the same process, i.e. upload video file to my server. Here is the issue, i don't know how to access video pointer binary like how i did for images using UIImageJPEGRepresentation, and send to my HTTP code?
-(void) assetsEmumeration {
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(#"See Asset: %#", result);
[assetArray addObject:result];
// get image url
NSURL *url = [[result defaultRepresentation] url];
NSString *urlInStr = [NSString stringWithFormat:#"%#",url];
NSData *imgData = UIImageJPEGRepresentation ([UIImage imageWithCGImage:[result thumbnail]], 90);
HttpUpload (imgData);
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
assetLibrary = [[ALAssetsLibrary alloc] init];
[assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) {
NSLog(#"Failure: %#", [error localizedDescription]);
}];
assetArray = [[NSMutableArray array] retain];
}
Could someone came across this to solve, please guide me!
You can get the raw bytes using ALAssetRepresentation's getBytes:fromOffset:length:error: method, something like this:
uint8_t *bytes = malloc([representation size]);
NSError *error = nil;
NSUInteger length = [representation getBytes:bytes fromOffset:0 length:[representation size] error:&error];

ALAssetsLibrary doesn't retrieve image URL's in physical iOS 4.1 iPod device?

I am trying to access iPhone's photo album photo images through ALAssetsLibrary. I could access all the photo albums and get the asset URL of each images on Simulator, via the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != NULL) {
NSLog(#"See Asset: %#", result);
// assets is a NSMutableArray..
[assets addObject:result];
// Here storing the asset's image URL's in NSMutablearray urlStoreArr
NSURL *url = [[result defaultRepresentation] url];
[urlStoreArr addObject:url];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
};
assets = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:assetGroupEnumerator failureBlock: ^(NSError *error) {
NSLog(#"Failure");
}];
urlStoreArr = [[NSMutableArray alloc] init];
}
-(void) GetURLImages
{
for (int i=0; i<[urlStoreArr count]; i++)
{
// To get the each image URL here...
NSString *str = [urlStoreArr objectAtIndex:i];
NSLog(#"str: %#",str);
}
}
It works as expected on iOS 4.0 Simulator, i.e, getting all the images URL's (ex: assets-library://asset/asset.JPG?id=1000000002&ext=JPG). But it doesn't retrieve image URL's on iPod 4.1 device. What could be the problem here? Can someone please help me fix so the code could also work on iPod? I'm totally confused.
Thank you!
Try what I mentioned in my comment or the following
library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
It also depends what photos you want.
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
}
[self.activity stopAnimating];
[self.activity setHidden:YES];
/* make */ group=nil;//otherwise it is enumerated thrice.
};

load the video type in the photo album using AssetsLibrary in objective C

i came across the following piece of code which loads everything from photo album but what should i do if i only wanted to load the video type in the photo album on a table?
thanks in advance.
void (^assetEnumerator)(struct ALAsset *,NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop){
if(result != nil){
NSLog(#"Asset:%#", result);
[Asset addObject:result];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop){
if(group != nil){
[group enumerateAssetsUsingBlock: assetEnumerator];
}
[self.tableView reloadData];
};
Asset = [[NSMutableArray alloc] init];
ALAssetsLibrary *Library = [[ALAssetsLibrary alloc] init];
[Library enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error){
NSLog(#"error occurred");
}];
Have a look at the -valueForProperty: instance method of ALAsset. Specifically, in your example with ALAsset *result:
if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo]) {
// asset is a video
}
I think this will be better.
if ([result valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) {
// asset is a video
}