- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我使用以下 ViewController.m 创建了一个新项目。当我运行该应用程序时,我可以看到一个具有预期原点/大小(38、100、250、163)的框,但它是黑色的并且没有播放视频。 Xcode 中有一个奇怪的输出:
2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay
2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
注意视频是用Videora iPhone Converter转换的,在Xcode中播放正常(所以不是视频问题);视频的路径没问题,因为当我指定 demo-iPhone1(它不存在)时,我得到一个 nil 异常。我在模拟器和 iPhone 上试过:总是黑盒子。有任何想法吗?
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(38,
100,
250,
163)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
最佳答案
我刚刚用这行代码解决了一个类似的问题。播放器 Controller 现在出现并且视频播放完美:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
//
@synthesize moviePlayer = _moviePlayer;
//
[self.moviePlayer prepareToPlay];
修改以适应您的环境。
关于iphone - 无法使用 MPMoviePlayerViewController 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12099393/
如何在我的应用程序中播放电影?我尝试使用此代码,但 xcode 给出了此错误: NSBundle *bundle = [NSBundle mainBundle]; NSString *moviePat
我对 MPMoviePlayerViewController 及其属性重复模式有疑问。据称,将其设置为 MPMovieRepeatModeOne 值将导致播放器重复播放。我使用以下代码循环播放视频,但
我在让 MPMoviePlayerViewController 工作时遇到问题。我有一个新项目,在 viewDidLoad 之后我尝试在 moviePlayerViewController 中播放电影
我的应用程序以电影开始,我尝试向下滑动或向下滑动以继续电影,但我不知道为什么手势不起作用,我尝试使用: [player view].userInteractionEnabled = NO; -(voi
我的 MPMoviePlayerViewController 存在问题:如果 Controller 在指定的 URL 处找不到电影,它会显示白屏,并且我无法使其关闭。 这就是我启动电影播放器的方式
我目前正在开发一个使用 MPMoviePlayerViewController 和 MPMoviePlayerViewController 的网络电视应用程序。 MPMoviePlayer 在 iPh
因此,我尝试了多种方法,结果相同。 我使用 YouTube MP4 URL 进行了测试,例如: This 我这样做的方式看起来很像: self.moviePlayer = [[MPMoviePlaye
我正在使用 cocos2d,我想播放电影。为此,我创建了 MPMoviePlayerViewController 并将其作为 [[CCDirector sharedDirector] openGLVi
MPMoviePlayerViewController(我使用快捷方式 MPVC)正确播放录制的肖像电影时出现问题。(在装有 iOS 6.0.1 的 iPhone 4S 上测试)该应用程序执行此操作:
我正在制作一个 iOS 视频播放器应用程序,它从 Web 服务获取一大堆视频 URL 并在 MPMoviePlayerViewController 中播放它们。 大部分视频只是 .mp4 或 .mov
这可能是重复的,但我没有得到我想要的。 我的应用程序只是基于纵向的,我想在其中仅在 MPMoviePlayerViewController 和 Landscape 模式下显示一个Video 文件。但无
我正在使用 MPMoviePlayerViewController 播放视频。 我将重复模式设置为 MPMovieRepeatModeOne,以便视频可以循环播放。 有什么方法可以用来获取播放视频的重
我有一个带有新闻提要屏幕的应用程序,就像 facebook 应用程序中的那个一样。为此,我制作了一个自定义单元格,它有一个 contentView,它是一个 UIView。此 contentView
我正在使用 MPMoviePlayerViewController 在我的应用程序中显示视频。有用!唯一的问题是电影播放前有黑色闪光。 如何去除黑色闪光?我看过其他线程,但它们似乎没有适用于 MPMo
我正在尝试为标题/启动屏幕加载一部小电影。但是,当我调用 presentMoviePlayerViewControllerAnimated 时,什么也没有发生。我已经确认该代码块正在执行,但用户无法感
我目前在 iOS 4.3.5 上运行,并尝试让我的 MPMoviePlayerViewController 在进入后台后继续播放。 我按照上面的描述实现了所有内容 http://developer.a
我会保持简单,代码如下: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)index
我正在尝试添加 subview MPMoviePlayerViewController 对象,它的顶部栏向下移动了一点,但如果我确实呈现了 MPMoviePlayerViewController 对象
这是我的代码,应该播放嵌入 subview 中的视频,但它只显示没有控件的静态图像。 - (void)displayVideo:(NSURL *)videoURL { if (self.med
我正在使用下面的代码来播放视频,但在使用表示资源文件路径的本地 url 时它工作正常。不适用于服务器网址。 player = [[MPMoviePlayerViewController alloc]
我是一名优秀的程序员,十分优秀!