Infinite Possibilities
Infinite Possibilities

Reputation: 7476

MPMoviePlayerController problems on iPad

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?

Upvotes: 3

Views: 7629

Answers (5)

umphreak
umphreak

Reputation: 11

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

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

Upvotes: 1

Infinite Possibilities
Infinite Possibilities

Reputation: 7476

Ok, guys, I found that this: is deprecated.

The solution is multimediaPlayer.controlStyle = MPMovieControlStyleDefault; but it still doesn't work.

Upvotes: 0

piyush
piyush

Reputation: 7

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
mp.moviePlayer.controlStyle = 2;

Upvotes: 0

fever
fever

Reputation: 11

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];
 }
}

Upvotes: 1

sagarkothari
sagarkothari

Reputation: 24820

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];
}

Upvotes: 4

Related Questions