开发者

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 vide开发者_StackOverflow中文版o, but the movie doesn't playing. Why it can be this problem?


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


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


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

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


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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜