我正在使用iOS 6中包含的mediaplayer框架来尝试从应用程序中播放电影。我导入,然后:
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}当调用此函数时,视图转到空白屏幕并无限加载。我已经尝试了这个实现的许多其他版本,结果各不相同,都失败了。is特殊情况下的日志为:
2012-11-05 21:19:27.900 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.902 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.977 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.978 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.984 [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-11-05 21:19:28.156 [MPAVController] Autoplay: Enabling autoplay有关于这个事业的想法吗?这是我第一次尝试玩视频,在这一点上它被证明是一场噩梦。
发布于 2012-11-06 21:11:07
在.h文件中添加以下内容
@property (nonatomic, strong) MPMoviePlayerController *controller;尝尝这个
-(IBAction)playMovie:(id)sender
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
[self setController:moviePlayerController];
}发布于 2013-01-17 10:55:52
Am facing the same issue, you can else try playing it on the web view.
NSURL *url = [NSURL fileURLWithPath:self.filePath];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.docWebView loadRequest:request];发布于 2014-08-14 12:24:07
代码的问题在于变量"moviePlayerController“只是局部作用域,所以在调用[moviePlayerController play];并退出函数后,局部变量立即被释放(因为这里有一个异步操作,其中包含从队列播放的play方法)。它不再保留引用URL的内容。所以你会看到一个黑屏和一个不定式“正在加载...”
您需要声明class的一个实例变量,并将内容从局部变量复制到class的属性,就像上面@iAppDeveloper中的示例代码一样。它应该是有效的!
https://stackoverflow.com/questions/13243903
复制相似问题