Search code examples
objective-cipadiphone-sdk-3.0

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?


Solution

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