MPMoviePlayerViewController quits unexpectedly - iphone

I'm trying to get videos to play from my server on the iPhone device. I'm using the following method to do so, however, it only works in the simulator; and on my iPhone 4. It doesn't work on iPhone 3G?
If I call this method on the iPhone 3G, it opens the video modal screen, starts to load the video, and then closes the modal screen abruptly. No errors are shown in the console.
The iPhone 3G has version 4.0 installed. My iPhone 4 has version 4.1.
Has anyone else experienced this?
-(IBAction)playMedia{
NSString* url = [self.data objectForKey:#"url"];
//initialize the movie player
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
//show a background image while the user waits
moviePlayerViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//show the movie
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[moviePlayerViewController release];
}

ok I got video to work on both iPhone 4 and iPhone 3G. Basically the issue was the file format. I was playing a .mov file. When I changed the format to .mp4, it now works on both devices. No change in code.
Hope this helps others with the same issue.

I'd do the above a little differently:
-(IBAction)playMedia{
NSString* url = [self.data objectForKey:#"url"];
//initialize the movie player
MPMoviePlayerViewController *tmpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
self.moviePlayerViewController = tmpPlayer;
//show a background image while the user waits
UIColor *tmpColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.moviePlayerViewController.view.backgroundColor = tmpColor;
self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//show the movie
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController];
[tmpPlayer release];
[tmpColor release];
}

Related

How would you save a thumbnail of a video to be placed in a CollectionView

I am working on an application that records a "videos", and save it to a folder in the documents directory. I was wondering how I would go about obtaining a thumbnail like in Photo's application. So that when the user clicks on it, I will play a video in full screen.
Here is a screenshot.
Maybe this can help you:
MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:fileUrl];
movie.shouldAutoplay = NO;
UIImage *image = [movie thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[movie release];

Getting blank white screen when presenting MPMoviePlayerViewController with no network connection

I am playing a media file present on the server. I purposely turned off the wifi connection in order to test the app. What I get is a blank screen.
What I want is to check before playing the video file is for internet connection. IF there is not connection, I dont want to play the video and display a alert message. How can I do so?
Can anyone help me on the same?
if ([[[UIDevice currentDevice] systemVersion ] doubleValue] >= 3.2) {
MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:urlAddress]];
if (mediaPlayer) {
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile ;
[mediaPlayer.moviePlayer play];
[mediaPlayer release];
}
}
See the Reachability sample application.

iphone MediaPlayerController does not show the media player

HI,
I am developing an app which contains 3 tab view control. One each for audio, video and images.
When i select the video tab, I have all the items displayed in the table view format so that on selection of any cell, the video is shown.
Example.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]] ;
[moviePlayer play];
}
The problem with this is though I am able to play the video I am unable to see the video and can hear only the audio.
In addition, if I were to close the app while the video is playing, and start it the app, the application crashes.
Can you please let me know how should I go ahead ?
After spending some more time, I have found out that for version above 3.2 one has to use MPMoviePlayerViewController.
The use of the same resolved the issue.
if ([[[UIDevice currentDevice] systemVersion ] doubleValue] >= 3.2) {
MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:urlAddress]];
if (mediaPlayer) {
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.moviePlayer.movieSourceType = MPMovieSourceTypeFile ;
[mediaPlayer.moviePlayer play];
[mediaPlayer release];
}
}
Check out this technote from Apple:
http://developer.apple.com/library/ios/#qa/qa2010/qa1240.html
To summarize, you need to add the movie player controller's view as a subview of your app's view.

Adding video files in iPhone

I am new to iPhone. I need sample code for how to add video files in iPhone.
Include the media player framework then do this:
MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"http://mywebsite.com/movie.mov"]]; // this can be an NSURL to a file in your bundle
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.view.backgroundColor = [UIColor blackColor];
[mediaPlayer release];
there are notifications and callbacks, but this is the basics.
you can find basically all the things you need here --> http://pdfcast.org/pdf/the-objective-c-programming-language ... download the pdf... enjoy!

Embedded Video in a UIView with iPhone

I would like to write an app that downloads (or streams) a video (encoded as required) in a view. I dont want to use the MPVideoPlayer from the SDK as it opens the video in full screen. I would like to place another UIView (transparent) over the video so that my users can annotate over the video.
Anyone have any idea or can point me to some code that will play video in a UIView?
If you want to do this you will need to include your own (software) video decoder, which will not have access to the hardware acceleration on the system. Even if you can get it working with acceptable performance it will be a huge battery drain.
If you wish to play a video in portrait mode, I have solution for that.
If you think that -MPMovie Player can run under a view, according to me it's not possible.
MP Movie player will work as Apple has designed.
So, MP Movie player will always / almost run in full screen.
Solution for portrait mode.
#interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
#end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
Hope that will help to you.
See, My question is very similar like yours.
playing video in custom size screen - view in iphone
Try this:
UIViewController *v = [[UIViewController alloc] init];
v.view.backgroundColor = [UIColor orangeColor];
NSString *path = [[NSBundle mainBundle] pathForResource:#"demo" ofType:#"mp4"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path])
{
NSLog(#"cannot find %# in bundle or doctuments", path);
}
NSURL *url = [NSURL fileURLWithPath:path];
MoviePlayerViewController *mpvc = [[MoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:mpvc.moviePlayer];
mpvc.moviePlayer.fullscreen = NO;
[mpvc.moviePlayer setControlStyle:MPMovieControlStyleNone];
mpvc.moviePlayer.view.frame = CGRectMake(10, 100, 300, 300);
[v.view addSubview:mpvc.moviePlayer.view];
[mpvc.moviePlayer play];
[self presentModalViewController:v animated:YES];
[v release];
Maybe you should check the MediaPlayer's private headers, and simply add the video's view as your view's subview.