代码之家  ›  专栏  ›  技术社区  ›  Ben Clayton

如何更改MPMoviePlayerViewController的UIModalTransitionStyle

  •  2
  • Ben Clayton  · 技术社区  · 16 年前

    当我使用mpmovieplayervewcontroller时,除了默认的向上滑动动画之外,我似乎无法将modalTransitionStyle更改为任何其他样式。

    有没有其他人设法让这个工作?

    MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]];
    theMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // doesn't work
    [self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
    

    3 回复  |  直到 16 年前
        1
  •  2
  •   Shaggy Frog    16 年前

    看着

    http://www.drobnik.com/touch/2010/07/the-3-2-hurdle-of-mpmovieplayercontroller/

    好像那里有密码 也 modalTransitionStyle 显示 MPMoviePlayerViewController 实例到相同的值。这样行吗?

        2
  •  6
  •   Ecarrion    13 年前

    我发现用CrossDisolve模式动画启动mpmovieplayervewcontroller实例的方法是在导航控制器中启动电影播放器,如下所示:

    NSURL * videoUrl = [[NSURL alloc] initFileURLWithPath:videoPath];
    MPMoviePlayerViewController * moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoUrl];
    
    UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:moviePlayerController];
    navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [navController setNavigationBarHidden:YES];
    
    [self presentViewController:navController animated:YES completion:nil];
    

    以及listen-to-MPMoviePlayerPlaybackDidFinishNotification通知:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
    

    -(void)movieDidFinish:(NSNotification *)notification {
    
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
        3
  •  0
  •   Dan    11 年前

    Ecarrion的回答非常有用——这里有一个快速的版本,希望能节省一些时间。

    import MediaPlayer
    
    class ViewController: UIViewController {
    
        ...
    
        func playAction() {
    
        // setup the media player view
        var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
        var moviePlayerView = MPMoviePlayerViewController(contentURL: url)
        moviePlayerView.moviePlayer.controlStyle = MPMovieControlStyle.None
        moviePlayerView.moviePlayer.repeatMode = MPMovieRepeatMode.None
    
        // register the completion
        NSNotificationCenter.defaultCenter().addObserver(self,
            selector: "videoHasFinishedPlaying:",
            name: MPMoviePlayerPlaybackDidFinishNotification,
            object: nil)
    
        // instantiate nav controller and add the moviePlayerView as its root
        var navController = UINavigationController(rootViewController:  moviePlayerView)
    
        // set transition (this is what overrides the animated "slide up" look
        navController?.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
        navController?.setNavigationBarHidden(true, animated: false)
    
        // present the nav controller
        self.presentViewController(navController!, animated: true, completion: nil)
    }
    
    
    func videoHasFinishedPlaying(notification: NSNotification){
        println("Video finished playing")
    
        self.dismissViewControllerAnimated(false, completion: nil)
        NSNotificationCenter.defaultCenter().removeObserver(self)
    
        let reason =
        notification.userInfo![MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]
            as NSNumber?
    
        if let theReason = reason{
    
            let reasonValue = MPMovieFinishReason(rawValue: theReason.integerValue)
    
            switch reasonValue!{
            case .PlaybackEnded:
                // The movie ended normally
                println("Playback Ended")
            case .PlaybackError:
                // An error happened and the movie ended
                println("Error happened")
            case .UserExited:
                // The user exited the player
                println("User exited")
            default:
                println("Another event happened")
            }
        }
    }
    
    推荐文章