ALAsset "real" filename - ios

I have transfered an MP4 from iTunes to my iPad. If I open the Videos app I can see it listed - there's the thumbnail and the filename below (my_file.mp4). However the actual filename of the asset is changed in iOS to some unique value - IMG_001.MOV, for example. I would like to get the the original filename as it is listed in the Videos app (my_file.mp4). How are where do I find this?
Thanks

Here is a Code to get the Real name of AssetsFile
ALAssetsGroupEnumerationResultsBlock assetsEnumerationBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (result) {
[self.arrAssetsMedia addObject:result];
}
ALAssetRepresentation *rep = [result defaultRepresentation];
if (rep.filename!=nil) {
NSLog(#"File name is::%#",rep.filename);
[arrMediaFileName addObject:rep.filename];
}
};
Note:ALAssetRepresentation has a property - (NSString *)filename with the help of this we can get the file name

You Can't get the MP4 file from your device with its original name.
The only way to retrieve the PhotoGallery item (photos/videos) from your device to your application is through ALAssetLibrary.
The items will have names such as assets-library://asset/asset.MP4?id=1000000001&ext=MP4
So you can track the URL and get the MP4 using ALAsset Library.

Related

iOS ALAsset is not refreshed after image is modified in photo library

My app can take image from photo library. For the first time app open, it can take latest image.
But after I open app, go to background, open photo library and modify image, and come back to app, when user choose photo, it is not the latest image.
When I log image url in assets, it show the same one before and after modify image. Is it supposed to be same? Or different after image is modified?
Asset = ALAsset - Type:Photo,
URLs:assets-library://asset/asset.PNG?id=4E226E36-2D9C-449C-92AE-5036938603A9&ext=PNG
- (void) loadAssetsForGroup: (ALAssetsGroup*) group withCompletionHandler: (void (^)(NSArray*)) completionHandler {
__strong NSMutableArray* assets = [NSMutableArray array];
[group enumerateAssetsUsingBlock: ^(ALAsset* result, NSUInteger index, BOOL* stop) {
if (!result) {
completionHandler(assets);
return;
}
[assets addObject: result];
}];
}

Retrieving videos uploaded from iTunes

I am creating an app that fetches photos and videos from the library.
I am using ALAssetsLibrary to fetch the contents from the library. But I can't retrieve the videos album from the library using this.
I am using the following code to retrieve the contents:
[library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop)
{
if (group || group.numberOfAssets >= 1)
{
[tmpAssets addObject:group];
}else{
self.assetAlbums = tmpAssets;
*stop = YES;
if(self.assetAlbums.count){
//parse contents and reload view
}
}
}
failureBlock:^(NSError *error)
{
//failed
}];
I am getting all other pictures and videos.
I have used a workaround of creating one videos album and filling its contents with the results from the ALAssetsLibraryGroupsEnumerationResultsBlock with allVideos filter.
but the ones that I upload from iTunes (those that get into the videos folder in the library) are not getting retrieved.

enumerateAssetsWithOptions return an alasset nil

i'm getting the user ALAssetsLibrary with this code
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
The problem that from time to time the alasset returns as a nil and i have no idea why. Most of the phones i tried it on, it was working fine but for some reason, other phones the alasset just returning as a nil.
iOS8 introduced the new Photos Framework. Many assets that used to be stored locally on the device are now stored in iCloud (i.e. not on the device). The Photos Framework is intended to be used when interacting with these assets (assets that may or may not be on the device).
My guess is that ALAssetLibrary returns nil for assets not stored locally on the device. Hence the issue you're encountering.
I have heard recently that iOS 8.1 rolled back this iCloud-related change, although I haven't been able to verify myself.
Hope this helps.

How can I keep track of media created/chosen by UIImagePickerController?

I'm building an iOS app that allows the user to upload videos from UIImagePickerController, either by recording or choosing them from the Camera Roll, as well as also play the chosen video. My question is, how would I go about keeping a reference to the videos that have been chosen this way? I want to do this so that if the video is still present on the device, I can use the local file rather than streaming the uploaded file.
When
imagePickerController:didFinishPickingMediaWithInfo:
returns, the URL in:
[info objectForKey:UIImagePickerControllerMediaURL];
Is in the format of: "file://localhost/private/var/mobile/Applications/ /tmp//trim.z2vLjx.MOV"
I'm lead to believe that the "/tmp/" directory is temporary, and therefore not suitable to save the URL for that location.
I can get all of the videos on the device through ALAssetsLibrary, but because I don't have a way of distinguishing them, this doesn't help me. I've been attempting to use:
[result valueForProperty:ALAssetPropertyDate];
To distinguish the videos, but I need a way of getting the creation date from UIImagePickerController for this to be useful.
I've finally managed to find a solution:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if(CFStringCompare((CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo)
{
//Dismiss the media picker view
[picker dismissModalViewControllerAnimated:YES];
//Get the URL of the chosen content, then get the data from that URL
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSData *webData = [NSData dataWithContentsOfURL:videoURL];
//Gets the path for the URL, to allow it to be saved to the camera roll
NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
{
ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
//The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
[lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
NSLog(#"created: %#", [asset valueForProperty:ALAssetPropertyDate]);
} failureBlock:^(NSError *error) {
NSLog(#"error: %#", error);
}];
}
}
As per usual, the solution was found by reading the documentation a little more thoroughly. Hopefully this'll help someone else out at some point.
You can easily keep a record of the videos you have on the device. Either by keeping a data base (which I think would be too much) or just a file with a list of your videos. In that list, you could have the URL of the assets.

Getting metadata from an audio stream

I would like to get the file name and, if possible, album image from a streaming URL in a AVPlayerItem that I am playing with AVQueuePlayer but I don't know how to go about doing this.
Also if it turns out that my streaming URL doesn't have any metadata can I put metadata in my NSURL* before passing it to the AVPlayerItem?
Thanks.
Well I am surprised no one has answered this question.
In fact no one has answered any of my other questions.
Makes me wonder how much knowledge people in here truly have.
Anyways, I will go ahead and answer my own question.
I found out how to get the metadata by doing the following:
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
NSArray *metadataList = [playerItem.asset commonMetadata];
for (AVMetadataItem *metaItem in metadataList) {
NSLog(#"%#",[metaItem commonKey]);
}
Which gives me a list as follows:
title
creationDate
artwork
albumName
artist
With that list now I know how to access the metadata from my audio stream. Just simply go through the NSArray and look for an AVMetadataItem that has the commonKey that I want (for example, title). Then when I find the AVMetadataItem just get the value property from it.
Now, this works great but it may be possible that when you try to get the data it will take a while. You can load the data asynchronously by sending loadValuesAsynchronouslyForKeys:completionHandler: to the AVMetadataItem you just found.
Hope that helps to anyone who may find themselves with the same problem.
When retrieving a particular item I would use the Metadata common keys constant declared in AVMetadataFormat.h, i.e.: AVMetadataCommonKeyTitle.
NSUInteger titleIndex = [avItem.asset.commonMetadata indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
AVMutableMetadataItem *metaItem = (AVMutableMetadataItem *)obj;
if ([metaItem.commonKey isEqualToString:AVMetadataCommonKeyTitle]) {
return YES;
}
return NO;
}];
AVMutableMetadataItem *item = [avItem.asset.commonMetadata objectAtIndex:titleIndex];
NSString *title = (NSString *)item.value;

Resources