加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone MPMoviePlayerViewController CGContext错误

发布时间:2020-12-14 19:51:41 所属栏目:百科 来源:网络整理
导读:我正在为iPhone制作一个应用程序,该应用程序将使用MPMoviePlayerViewController播放一些电影.到目前为止,我已经得到了播放电影,但是它在调试器中抛出一些错误,所有这些都从CGContext开始.我试图修复我的大脑.以下是我的代码的细节: .h文件: #import UIKit/
我正在为iPhone制作一个应用程序,该应用程序将使用MPMoviePlayerViewController播放一些电影.到目前为止,我已经得到了播放电影,但是它在调试器中抛出一些错误,所有这些都从CGContext开始.我试图修复我的大脑.以下是我的代码的细节:

.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; 
}

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

<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意味着这些特定的变量没有值,但我不知道如何补救这个.任何帮助将不胜感激.

解决方法

我有同样的问题.只说这个:

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

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

从Norman的解决方案中提取一下,我简单地将这个调用包装在一个人造绘图环境中,就像这样:

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

这是愚蠢的,但它的作品.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读