Fetching video through file name from video gallery in iphone - iphone

I have name of some videos which are going to be stored in video gallery of iphone, can I get the url of the video I specify through file name, i.e. if I specify a.png video name then it should return the url of that video.

It sound like you want to access a video in the user's folders directly. You can not do this.
Instead you must get the user to select a Video using a standard picker, something like this:
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
See this question.

Related

commonMetadata array empty for some songs from iPod library

I'm using a MPMediaPickerControllerto enable the user to pick songs from the device's iPod library. Then I put this songs into an array (in this case playerQueue) and use an AVPlayer instance to play one song after the other:
- (void)setQueueWithItemCollection:(MPMediaItemCollection *)theCollection {
for (MPMediaItem *theMediaItem in theCollection.items) {
NSURL *mediaURL = [theMediaItem valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *thePlayerItem = [AVPlayerItem playerItemWithURL:mediaURL];
// Don't add protected tracks to queue as they cannot be played
if (!thePlayerItem.asset.hasProtectedContent && thePlayerItem.asset.isPlayable) [self.playerQueue addObject:thePlayerItem];
// Further implementation
}
}
Now I get the song title using this code snippet (with AVPlayer *musicPlayer):
AVPlayerItem *currentItem = self.musicPlayer.currentItem;
AVAsset *asset = currentItem.asset;
// Further implementation
NSLog(#"DEBUG: Meta data: %#", asset.commonMetadata);
NSArray *titles = [AVMetadataItem metadataItemsFromArray:asset.commonMetadata withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
Most times this works without any problem. But there are are also songs for which asset.commonMetadata returns an empty array. However the Music app on my iPhone is able to display the song title (and album artwork etc.) just like iTunes (on the Mac).
The song file is an Apple MPEG 4 Audio file purchased from the iTunes Store.
Why is asset.commonMetadata returning an empty array even though there are meta data available?
I was having this same problem with downloaded m4b audio files. Turns out that AVURLAsset requires the URL string to end in '.m4b' (other audio extensions would work, I suspect). You can't use the URL as is if it is something like http://source.com/download.php?id=12345. Otherwise, the asset.commonMetaData just returns an empty array. I don't know if this is a problem with iTunes assetURLs, but it would be easy to check.
The only solution that worked for me:
Use AudioToolbox.framework to retrieve metadata from such files, i.e. use AudioFileGetProperty function.
It seems like a real bug in AVFoundation…

Video searching

I'm developing app for IPhones where users clicks button, gets the list of all videos from his IPhone and uploads chosen video to server.
I know how to upload video to server, but I don't know how to implement video searching.
How can I get pathes to all videos (in users IPhone) in Array?
(Currently my IPhone is unavailable for use, so I'd like to know also how to test video search in IPhone Simulator?)
Kind Regards
You need to use the UIImagePickerController component, configuring it to show only videos when browsing the library.
You can do that by setting the mediaTypes property of the picker in this way:
myImagePickerController.mediaTypes =
[[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Then if you want to test it in the simulator, you need to save some videos on it and you can use the UISaveVideoAtPathToSavedPhotosAlbum function to achieve that. Check out this great answer for more detailed instructions.
This link shows how to access only videos from the photoroll since all videos of the device should be stored there, you should be able to access them from there: Picking video from PhotoLibrary with UIImagePickerController in OS 3.1

how to get iphone ipod playlist images and display it in image view

I am working with iphone ipod to read the album and playlist and play it in my application.
My question is that that i get the image from the album i have selected. and it is also working well in my application.
But i never get images from the playlist which i have selected their are different songs in my playlist and also having different image for that songs. for the album i have get the code and it work great. i am new for this and i cant found any reference code for this.
And i am using AVPlayer to play the songs.
So please help me and provide some sample code. for how to get all images from playlist and convert that image to data in iphone.
Please help me.
You're looking for is the MPMediaItemPropertyArtwork for MPMediaItem. As stated in the docs. After getting the artwork property you can make a MPMediaItemArtwork object, as stated in the docs.
An MPMediaItemArtwork object, or media item artwork, represents a graphical image, such as music album cover art, associated with a media item. Media items are described in MPMediaItem Class Reference.
With this you can do something like this. Assuming song is an MPMediaItem:
UIImage *image = nil;
MPMediaItemArtwork *itemArtwork = [song valueForProperty:
MPMediaItemPropertyArtwork];
if(itemArtwork != nil)
image = [itemArtwork imageWithSize:CGSizeMake(100,100)];
Now you have image containing your MPMediaItem artwork, set it to your image view ([myImageView setImage:image]). Keep in mind, this will only work if artwork IS available.
Hope this helps.
You can use VTM_AViPodReader demo for this.

Save MP4 into iPhone photo album

I have an app that plays video clips through the MPMovieplayer. These clips are in mp4 format and everything works dandy. I want to take that same clip and save it into the photo album. This works if I manually sync the video from a computer through iTunes to the phone. It appears to transcode the video file and store it as a .MOV format.
However, when I try and save the video while in the app via code, I get a video format error. So my question is how do I get my video to save in the photo album? If this is not possible with mp4 how do I transcode (in app) to .MOV?
Here is the code:
ALAssetsLibrary* library = [[ALAssetsLibrary alloc]init];
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:moviePlayerController.contentURL])
{
NSURL *clipURl = moviePlayerController.contentURL;
[library writeVideoAtPathToSavedPhotosAlbum:clipURl completionBlock:^(NSURL *assetURL, NSError *error)
{
if (error)
[ErrorAlertView showError:error];
else [ErrorAlertView showErrorTitle:#"Success" message:#"Your video clip is saved"];
}];
}
[library release];
Is your contentURL a file path URL or a web URL? For the writeVideoAtPathToSavedPhotosAlbum method, in my testing you actually need a file path URL created (for example) in this way:
NSString *pathString = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"mp4"];
NSString *pathURL = [NSURL fileURLWithPath:pathString isDirectory:NO];
This means you need to first download the movie from the web, if you're using a web URL. I recommend ASIHTTPRequest, using the setDownloadDestinationPath: method to set the download directory.
In general, mp4 files should work if they're the right resolution for the right (retina, non-retina, iPad) device (see my tests of supported video files here).
If the video still gives a NO response on videoAtPathIsCompatibleWithSavedPhotosAlbum: after making absolutely sure the file path URL is correct, then you'll need to use AVAssetExportSession (with AVAssetExportPresetLowQuality, AVAssetExportPresetMediumQuality, or AVAssetExportPresetHighestQuality) to get a device-appropriate file that you can then save to the Photo Album.

How to Play Videos Files from an iPod Video Library?

How can I play video files in my application from an iPod video library? Is there any other possibility to search and play video files stored anywhere in an iPhone?
You can't The iPod Library access is audio only at this time. There is currently no way to access any video outside of your application sandbox (in other words, you can only search through and play video your app has downloaded itself).
If you need access to the video library you should file a bug with Apple describing why you need it.
You can play video files store in device, there are 3 places you can search :
Camera Roll : video recorded
iPod Library
File Sharing
After searching on internet I found this sample of Apple describe how to get and play those videos.
Here is AVPlayerDemo
Hope this will help you. Good luck :)
MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInteger:MPMediaTypeMovie] forProperty:MPMediaItemPropertyMediaType];
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate:predicate];
NSArray *items = [query items];
NSURL url = [[NSURL alloc]init];
for (MPMediaItem item in items)
{
//get the Title of video
NSString* title = [item valueForProperty:MPMediaItemPropertyTitle];
NSLog(#"title %#",title);
//get the path of Video
url = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSLog(#"url %#",url);
}