我正在为 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
我知道这invalid context 0x0
意味着那些特定的变量没有值,但我不知道如何解决这个问题。任何帮助将不胜感激。