MPMoviePlayerController on iOS5


#1

Hi from Japan!

I now enjoy learning iOS with this nice textbook (Thank you, authors!)
after reading “Cocoa Programming for Max OS X”.

Well, today, I ran into a problem on MPMoviePlayerController on iOS5.
The movie didn’t start when I ran the code on the book.
I’ve tried everything and found a simple solution: Add one line to ‘init’ method as below:
And, now it seems to be working nicely. Hope this helps.

– Takeshi

- (id)init
{
    self = [super initWithNibName:@"MediaPlayerViewController" bundle:nil];

    if (self) {

        NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"Layers"
                                                              ofType:@"m4v"];
        if (moviePath) {
            NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
            moviePlayer = [[MPMoviePlayerController alloc]
                                    initWithContentURL];

            // I added this line. You can try other modes, of course!
            [moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
        }

        NSString *musicPath = [[NSBundle mainBundle] pathForResource:@"Music"
                                                              ofType:@"mp3"];

#2

Great Job!

Thanks!


#3

Thank you very much

You are my savior.


#4

hi guys. you’re more than welcome.


#5

Alternatively just add [moviePlayer play] in the viewDidLoad method after you are done setting the frame for the MoviePlayer’s View.

But I don’t know why it doesn’t show the play controls by default.