在iOS应用程序中播放视频:有音频但没有图像
我想要在我的 iPhone 应用程序中播放一段短视频。当我使用下面的代码时,我只能听到音频并看到 应用程序的常规视图。我希望视频在此视图之上播放。 对此我能做什么?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
i want a short video to play in my iphone app. When i use the code below, i only hear the audio and see
the regular view of the app. I want the video to play on top of this view.
What can i do about this?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要混淆
MPMoviePlayerController
和MPMoviePlayerViewController
。当您使用MPMoviePlayerController
时,请像这样使用它(通常用于 iPad 上的嵌入式视频):当您使用
MPMoviePlayerViewController
时,然后使用呈现视频>presentMoviePlayerViewControllerAnimated:
(通常用于全屏视频)。Don't mix up
MPMoviePlayerController
andMPMoviePlayerViewController
. When you useMPMoviePlayerController
use it like this (typically for embedded videos on the iPad):When you use
MPMoviePlayerViewController
then present the video withpresentMoviePlayerViewControllerAnimated:
(typically for fullscreen videos).对我有用的唯一魔法是
在头文件
更多详情
The only magic that worked for me was
In Header file
More Details