views:

174

answers:

1

Hey guys,

I'm having trouble getting MPMoviePlayerController to work on the device. It runs fine in simulator, playing a five-second video and then sending the appropriate callback (myMovieFinishedCallback:) to the view controller. When it runs on the device, the movie never shows up, even though I can trace through [player play] with no problems. myMovieFinishedCallback: is never called, and there are no errors. All the right resources are being copied. Any idea what's going on?

Here's the code I use to create and use the player,

Update: I've switched over to using MPMoviePlayerViewController. On the device the movie still does not play, I just get the spinning progress wheel indefinitely. The controls also flash briefly even though I've set the player to MPMovieControlStyleNone - anybody know how I can fix this? The movie is five seconds and about 1.5 MB if that makes any difference.

Update: Other movie files work, but I can't figure out how to make mine work. I've tried it as a .mov and a .mp4 and the settings seem to be right. Any idea what would cause the MPMoviePlayer to show a progress wheel forever on the device only?

- (void) playMovie
{
    NSString *url = [[NSBundle mainBundle] 
                     pathForResource:@"myMovie" 
                     ofType:@"mp4"];

MPMoviePlayerViewController *playerViewController = 
[[MPMoviePlayerViewController alloc] 
 initWithContentURL:[NSURL fileURLWithPath:url]];

playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;

[[NSNotificationCenter defaultCenter] 
 addObserver:self
 selector:@selector(myMovieFinishedCallback:)
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:[playerViewController moviePlayer]];

playerViewController.view.frame = movieView.frame;

[movieView addSubview:playerViewController.view];

//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}   
+2  A: 

Your code works fine for me, so there are two possibilities that come to mind (there may be others):

  1. You movieView has not been properly initialized or has not had its frame set so that it's visible.
  2. The video format of the video you're displaying isn't supported on the device.

I would try using a different video. Maybe one you can confirm you've played on the device before. Here's the little demo project I threw together: http://www.cimgf.com/files/PlayMovie.zip

Matt Long
This was a big help - your rollercoaster video works. I've tried messing with the settings for the video I'm using but still no luck. Has anyone had a similar problem with MPMoviePlayer?
Luke
I suggest that you start a new question asking about formats and the MPMoviePlayer. The title of this question won't necessarily get the attention of people who know about formats. One more thought. If you're on iOS 4, have you tried using the AVFoundation classes. AVPlayer and AVPlayerLayer allow you to display a video in a Core Animation layer.
Matt Long
I'm not in iOS 4 because we're on the iPad. Can I ask how you made that rollercoaster movie? We've tried a variety of different converters and still have had no luck.
Luke
That's actually a movie that Apple used to include in a new OS X install. I've copied it over between version upgrades just for testing purposes. I don't know anything more about it. If you open it in QuickTime Player, you can "Get Info" on the video file to see certain details about it.
Matt Long
Actually just noticed it's still there. Look in /System/Library/Compositions and you'll see several .mov files in the same format.
Matt Long
you using ios4 but u r not regestering to // Register that the load state changed (movie is ready) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil]; register to that know whether it is calling or not.
jeeva
@Matt Long I created a AVPlayer and added it to AVPlayerLayer but only audio is hearing but no video... any answer NSString *path = [[NSBundle mainBundle] pathForResource:@"Mto" ofType:@"mov" inDirectory:nil]; NSURL *movieURL = [NSURL fileURLWithPath:path]; player = [[AVPlayer alloc] initWithURL:movieURL]; playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; [[self.view.layer superlayer] addSublayer:playerLayer]; if (playerLayer.readyForDisplay) { NSLog(@"Ready "); } [player play];
jeeva