Video just doesn't want to play


I understand that the way video plays on >=3.2 is different but even with the new code I just cannot get the video to play - have been struggling for too long!

Do anyone have any ideas? I even started a new project to try and nothing happens not even an error message:

[code]- (void)viewDidLoad
[super viewDidLoad];

NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"Layers" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL];

if (mp)
	// save the movie player object
	//self.moviePlayerViewController = mp;
	//[mp release];
	[self presentMoviePlayerViewControllerAnimated:mp];
	mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
	[mp.moviePlayer play];
	[mp release];



Have you seen this post?

I had asked Joe about any issues that might pop up in the book when working with iOS4, and he shared this for the video code. Not sure if it addresses your problem, but worth a look just in case.


I was able to find a simple fix for this bug without actually going through the ViewController solution that Joe suggests (Not that it is a bad suggestion, I just found this to be much simpler).

I searched through the documentation for the MPMoviePlayerController and stumbled across a property that seems to work perfectly. I am definitely no expert, but I believe it is simply defaulted to a bad value for the task we are trying to accomplish. I added the following line to my viewDidLoad: method in the MediaPlayerViewController.m file:

[moviePlayer setScalingMode:MPMovieScalingModeAspectFit];

So the final code for this method looks like this:

- (void)viewDidLoad
    [[self view] addSubview:[moviePlayer view]];
    float halfHeight = [[self view] bounds].size.height / 2.0;
    float width = [[self view] bounds].size.width;
    [moviePlayer setScalingMode:MPMovieScalingModeAspectFit];
    [[moviePlayer view] sizeThatFits:CGSizeMake(width, halfHeight)];
    [[moviePlayer view] setFrame:CGRectMake(0, halfHeight, width, halfHeight)];

After this change, it works perfectly.

Hope this helps anyone who is stuck.