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(); 这是愚蠢的,但它的作品. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 基于flash cs3 actionscript3.0的mp3网络播放器
- ruby-on-rails – 使用范围(标记符?)和上下文的行为作为标
- ruby – 复杂的DataMapper查询关联
- ruby-on-rails – 是否有免费的方式以编程方式发送短信?
- 相等 – 在Swift 2.0中使用equals运算符和NSObjects的Bug?
- ruby – 如何告诉Rubocop忽略一个特定的目录或文件
- c# – 强制在抽象超类的子类中使用属??性
- swift中的SequenceType和CollectionType有什么区别?
- ios – 从Xcode项目中删除空行
- 使用AJAX实现优酷视频播放时留言不刷新