当我使用MPMoviePlayerViewController时,我似乎无法将modalTransitionStyle更改为默认的向上滑动动画以外的任何内容。
还有没有其他人能让它正常工作呢?
MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoURL]];
theMoviePlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; // doesn't work
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];谢谢
发布于 2010-09-11 02:15:04
看着
http://www.drobnik.com/touch/2010/07/the-3-2-hurdle-of-mpmovieplayercontroller/
这里的代码似乎也将呈现MPMoviePlayerViewController实例的视图控制器的modalTransitionStyle设置为相同的值。这行得通吗?
发布于 2013-06-07 06:06:40
我发现使用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];和listen to MPMoviePlayerPlaybackDidFinishNotification通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];并在视频结束后将其关闭:
-(void)movieDidFinish:(NSNotification *)notification {
[self dismissViewControllerAnimated:YES completion:nil];
}发布于 2014-12-14 01:35:36
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")
}
}
}https://stackoverflow.com/questions/3685901
复制相似问题