How to Play Videos Files from an iPod Video Library? - iphone

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);
}

Related

Detecting music video from iPhone/Pad music library

Im using MPMediaQuery to search the library on a user's iPhone/Pad. Im able to return audio tracks but im unable to return any of the videos which are on the device. Apparently its not possible according to this article but i fail to understand why this would be. If that is true, is there another way to retrive this information?
This is how im retrieving tracks
MPMediaQuery *queryTracksByArtist = [MPMediaQuery artistsQuery];
MPMediaPropertyPredicate *pred = [MPMediaPropertyPredicate predicateWithValue:#"The Album Title" forProperty:MPMediaItemPropertyAlbumArtist comparisonType:MPMediaPredicateComparisonContains];
[queryTracksByArtist addFilterPredicate:pred];
NSArray *itemsFromGenericQuery = [queryTracksByArtist items];
No, As of now, you cannot access video with ipod library access. check this link.

Playing a video in ipad

I want to play a movie in my app and the video is stored in my ipad library.
Can anyone provide me the necessary guidance for it?
Get the MPMediaItem of the video you want using MPMediaQuery
Get the Asset URL like this:
NSURL *videoURL = [mediaItem valueForProperty:MPMediaItemPropertyAssetURL];
Instantiate an MPMoviePlayerViewController using videoURL as the content URL.
If the video is stored in your App's bundle then do this to get the URL:
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"nameoffile" withExtension:#"mp4"];
See a sample of a custom view/viewController combo in Pragmatic iPad Programming. Check the source code for chapter 8 (free download from that page). They use a video provided as a file inside the project. Btw, if the file in the video appears red in XCode, you'll have to remove it and re add it, I think the project definition is a bit screwed.

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 play the video using “HTTP Live Streaming” in iphone?

I am new to iphone development,I am parsing a XML URL and display its content in the table, when i click a row , its corresponding parsed tube URL is played using the movie player.I am using media player framework.Here is my code
NSURL *movieURL = [NSURL URLWithString:requiredTubeUrl];
if (movieURL)
{
if ([movieURL scheme])
{
MoviePlayerController *myMovie = [[MoviePlayerController alloc]init];
[myMovie initAndPlayMovie:movieURL];
}
}
This is working fine, but i want to play the video using "HTTP Live Streaming".How can i do that? Any tutorials and sample code would me more helpful.Thanks.
Apple provides and overview and some sample pages with streams. You provide the playlist file (.M3U8) URL to your MPMoviePlayer instance. If your server is set up properly, the .M3U8 file URL should suffice.
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008332-CH1-DontLinkElementID_29
To implement in for the browser, which applies for a lot to native app development since it directs iphone users to movie app. A lot depends on the proper stream you're wanting to view http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/
Use MPMoviePlayerController for streaming from server.
-(void)initAndPlayMovie:(NSURL *)movieURL
{
// Initialize a movie player object with the specified URL
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
if (mp)
{
[self.moviePlayer play];
}
}

What's the SIMPLEST way to play a sound clip in an iPhone app?

I want to be able to play a sound clip in an iPhone OS app. I've seen info on both NSSound as well as AVFoundation as being means for getting sound clips played on an iPhone OS device, but I'm still not clear on the subject and could use some help. No need to spell it out for me step-by-step in actual code, but if someone could give me a hint as to the general direction (i.e. which classes I should be focusing on) in which I should start moving I'll fill in the blanks myself. So, what's the SIMPLEST way to play a sound clip in an iPhone app?
Apple has an article on this subject, see: this link
AVAudioPlayer is the simplest way to play sounds of any length, looping or not, however it requires iPhone OS 2.2 or higher. A simple example:
NSString *soundFilePath =
[[NSBundle mainBundle] pathForResource: #"sound"
ofType: #"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer =
[[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: nil];
[fileURL release];
[newPlayer play];
[newPlayer release];
It will play virtually any file format (aiff,wav,mp3,aac) Keep in mind that you can only play one mp3/aac file at a time.
Here's the simplest way I know of:
Convert your sound file to caf (use afconvert commandline tool) and add to your project.
caf stands for Core Audio Format (I think...)
Look for SoundEffect.h and .m in Apple's sample code. I believe both Metronome and BubbleLevel have it.
Copy to your project
Write code like below:
SoundEffect *SimpleSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:#"soundfile" ofType:#"caf"]];
[SimpleSound play];
[SimpleSound release];
Study SoundEffect.m to get an idea of simple sound handling.