views:

2137

answers:

6

Hello guys!

I'm trying to use the MPMoviePlayerController class on the iPad.

here's my code:

            multimediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];               
            multimediaPlayer.movieControlMode = MPMovieControlModeDefault;
            [multimediaPlayer play];

and this works very well on the iPhone but it don't want to run on the iPad. I hear the sound of the video, but the movie doesn't playing. Why it can be this problem?

A: 

Ok, guys, I found that this: is deprecated. The solution is multimediaPlayer.controlStyle = MPMovieControlStyleDefault; but it still doesn't work.

Infinity
Did you get an answer for ur Q? I am also stuck in the same thing.
wolverine
if you have an answer can you share with us ?
hib
You have to add the MPMoviePlayerController's view to your view, but if you read carefully the new documentation you can see that this is a big advantage. I hope this helps you.
Infinity
now it will work see my answer - i Had the same issue at initial.
sugar
A: 

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

mp.moviePlayer.controlStyle = 2;
piyush
A: 

Something along these lines is probably what you want to do:

MPMOviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentUrl:movieUrl];
[self presentMoviePlayerViewController:mpvc];

umphreak
A: 

MPMoviePlayerViewController works fine in full screen mode. But have an issue when back/forward seek buttons are clicked, video exists and removed from the view completely. If I do same steps repeatedly the video shows blank screen with audio being playing in background.

Generally the back/forward seek buttons are working weirdly.

Did you guys having the same problem? And fixed the issue.

Veer
I have had lots of problems with the back/forward buttons when trying to play a video on the iPad. I have resorted to placing some transparent views over the controls, essentially disabling them, until I can figure out a more appropriate way to handle this.
AidenMontgomery
+1  A: 

Below code working perfect for my application. Hope it would do same for you. The main thing is to set the frame of mpMoviePlayerController's frame. if you don't do it, it would almost not show the video.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [[UIApplication sharedApplication] setStatusBarHidden:YES];

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayBackDidFinish:) 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];

    // Register to receive a notification when the movie scaling mode has changed. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(movieScalingModeDidChange:) 
                                                 name:MPMoviePlayerScalingModeDidChangeNotification 
                                               object:nil];
    kDomain = [NSString stringWithString:@"http://www.virtua-book.com/"];
    [navigationController setNavigationBarHidden:YES];

    NSURL *ur=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:@"IPAD" ofType:@"mp4"]];
    mpMCtr=[[MPMoviePlayerController alloc] initWithContentURL:ur];
    mpMCtr.fullscreen=YES;
    [mpMCtr setScalingMode:MPMovieScalingModeFill];
    [mpMCtr setShouldAutoplay:YES];
    [mpMCtr setControlStyle:MPMovieControlStyleNone];
    [mpMCtr setMovieSourceType:MPMovieSourceTypeFile];
    mpMCtr.view.frame = CGRectMake(0, 0, 1024, 768);
    [mpMCtr setRepeatMode:MPMovieRepeatModeNone];

    [mpMCtr play];

    [ur release];

    // Override point for customization after app launch    
    [navigationController.view addSubview:mpMCtr.view];
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

    return YES;
}


//  Notification called when the movie finished playing.
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
    [mpMCtr.view removeFromSuperview];
}
sugar
Thanks for correcting me.
Infinity
+1  A: 

To fix back/forward (or previous/next) buttons you should do the following:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

...

- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification {
 if (moviePlayer.playbackState == MPMoviePlaybackStateStopped) {
  [moviePlayer setContentURL:[moviePlayer contentURL]];
  [moviePlayer play];
 }
}
fever