iphone MPMoviePlayerViewController CGContext错误 [英] iphone MPMoviePlayerViewController CGContext Errors

查看:127
本文介绍了iphone MPMoviePlayerViewController CGContext错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone编写一个应用程序,它将使用 MPMoviePlayerViewController 播放一些电影。到目前为止,我已经得到它来播放电影,但它在调试器中抛出一些错误,所有错误都以 CGContext 开头。我试图解决它已经破坏了我的大脑。以下是我的代码的详细信息:

I am writing an app for the iPhone that will play some movies utilizing MPMoviePlayerViewController. So far I have gotten it to play movies, however it is throwing some errors in the debugger that all start with CGContext. I have wracked my brain in trying to fix it. Here are the details of my code:

.h文件:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface MovieViewController : UIViewController {
    MPMoviePlayerViewController *playerController;
}

-(IBAction) playMovie:(id)sender;

.m文件:

@interface MovieViewController ()
@end
@implementation

-(IBAction)playMovie:(id)sender {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"moviename" ofType:@"mp4"]];
playerController =  [[MPMoviePlayerViewController alloc]
                     initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
playerController = nil; 
}

当我运行程序时,电影将播放,但是当代码执行时line: playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 发生以下错误:

When I run the program the movie will play, however when the code executes the line: playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; the following errors occur:

<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextClipToRect: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextDrawShading: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0

我知道无效的上下文0x0 意味着这些特定变量没有值,但我不知道如何解决这个问题。任何帮助将不胜感激。

I do know that invalid context 0x0 means that those specific variables do not have a value, but I have no idea how to remedy this. Any help would be greatly appreciated.

推荐答案

我遇到了同样的问题。仅仅这样说:

I was having the same issue. Merely saying this:

MPMoviePlayerViewController* mpvc = 
    [[MPMoviePlayerViewController alloc] initWithContentURL: m];

导致这些无效上下文错误消息。视图控制器的视图(全屏播放器)确实出现了,播放电影没问题;唯一的问题是这些错误消息,我不想在控制台中显示。

was causing these invalid context error messages. The view controller's view (the fullscreen player) did appear when presented, and played the movie no problem; the only issue was these error messages, which I didn't want showing up in the console.

从Norman的解决方案中得到一个提示,我只是简单地将调用包裹起来绘制上下文,如下所示:

Taking a hint from Norman's solution, I simply wrapped the call in an artificial drawing context, like this:

UIGraphicsBeginImageContext(CGSizeMake(1,1));
MPMoviePlayerViewController* mpvc = 
    [[MPMoviePlayerViewController alloc] initWithContentURL: m];
UIGraphicsEndImageContext();

这很愚蠢,但确实有效。

It's silly, but it works.

这篇关于iphone MPMoviePlayerViewController CGContext错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆