MPMoviePlayerViewController customization

前端 未结 3 1895
长发绾君心
长发绾君心 2021-02-04 19:12

I\'m using MPMoviePlayerViewController - with the player controls set to: MPMovieControlStyleFullscreen

I\'m having a problem with some of buttons that are in MPMovieCon

3条回答
  •  你的背包
    2021-02-04 19:51

    First off, MPMoviePlayerController is a little different than MPMoviePlayer*View*Controller, so some of these answers lead to problems when converting applications that were built in an iOS 4.3+ environment.

    I've built some apps using MPMoviePlayerController that worked fine when built in iOS 3.2. When I rebuilt it with XCode 3.2.6, (iOS 4.3), the videos don't even play on the iPhone. I since fixed that by adding the MPMoviePlayerController instance to a subView, then presenting a modal (Player is a UIViewController) with the movplayer in fullScreenMode:

    //from didSelectRowAtIndexPath
    
    Vid *selected = [items objectAtIndex:position];
    
    player = [[Player alloc] init]; 
    movplayer = [[MPMoviePlayerController alloc] initWithContentURL:selected.vidURL];
    movplayer.view.frame = player.view.bounds;
    movplayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | 
    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
    [player.view addSubview:movplayer.view];
    [self presentModalViewController:player animated:YES];
    [movplayer setFullscreen:YES animated:NO];
    [movplayer play];
    [player release];
    
    //movplayer is released inside - (void)exitedFullscreen:(NSNotification*)notification 
    

    This was done on account of the UINavigationBar being half cut off when rotating.

    When I got to the iPad version of the app the modal option wouldn't work aesthetically. It was also having the UISplitViewController navBar and toolbars half cut off when rotating in full screen mode. So I tried implementing MPMoviePlayerViewController instead of MPMoviePlayerController. With this conversion, XCode gave me errors when trying to set:

    movplayer.controlStyle = MPMovieControlStyleEmbedded;
    

    The proper way to do this with a MPMoviePlayerViewController is:

    movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    

    When the player is added as a subView, the pinch gestures will toggle the player between fullScreen and the size of your parentView (player.view.bounds) smoothly, as well as preserve the toolbars and navBars native to the parent.

    //iPad version with a view (viewForMovie) inside the DetailViewController
    movplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[current vidURL]];
    movplayer.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
    movplayer.view.backgroundColor = [UIColor clearColor];
    movplayer.view.frame = viewForMovie.bounds;
    [viewForMovie addSubview:movplayer.view];
    

    So these two examples show some workarounds for those who want to convert their iPhone or iPad apps to a newer iOS version.

提交回复
热议问题