我得到了这段代码:
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:@"/Resources/disc.mp4"]];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];
但我真的不知道如何将视频添加到我的项目中。我必须将视频文件放在哪个文件夹中!?或者我是否必须执行其他操作才能将其添加到我的项目中?
编辑:
在xcode中看起来是这样的,对吗? 因为我现在确实遇到播放错误。 以前我使用一个 url 来播放这个视频并且效果很好,但是这个文件在本地没有 :(
最佳答案
好的,您的 bundle 路径看起来很麻烦,下面应该可以工作。
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"disc" ofType:@"mp4"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];
关于iphone - iOS 使用 MPMoviePlayerController 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17578965/