2010-09-10 45 views
2

当我使用MPMoviePlayerViewController时,我似乎无法将modalTransitionStyle更改为除默认向上滑动动画以外的任何其他内容。如何更改MPMoviePlayerViewController的UIModalTransitionStyle

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

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

感谢

回答

2

看着

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

看来码有将呈现MPMoviePlayerViewController实例相同值的视图控制器的modalTransitionStyle。那样有用吗?

+4

谢谢毛茸茸的。实际上它并不是很有效 - 但是在你指向我的代码中存在秘密。如果你使用新的[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];那么过渡样式将被忽略。但是,如果使用标准[self presentModalViewController:animated:],那么它适用于转换INTO电影,但在电影结束时仍然使用默认的幻灯片动画。奇! – 2010-09-13 09:56:09

+0

..哦,这个链接有一些非常好的提示,使3.1/2和4.0兼容电影播放。干杯! – 2010-09-13 09:56:51

6

,我发现有CrossDisolve模式动画推出'MPMoviePlayerViewController'实例的方法是启动电影播放器​​,导航控制器内部,就像这样:

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

和听MPMoviePlayerPlaybackDidFinishNotification通知:

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

,并关闭它在视频播放完毕:

-(void)movieDidFinish:(NSNotification *)notification { 

    [self dismissViewControllerAnimated:YES completion:nil]; 
} 
+1

非常感谢你,我正在寻找这个年龄!谢谢 :) – 2014-07-23 09:04:57

0

Ecarrion的回答非常有帮助 - 这里有一个Swift版本,希望能为他节省一些时间。

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") 
     } 
    } 
} 
相关问题