我尝试将视频添加到Viewcontroller但总是失败:有人可以提供帮助吗?
-(id) init
{
// always call "super" init // Apple recommends to re-assign "self" with the "super's" return value
if(self=[super init])
{
//play // [[[CCDirector sharedDirector] view] addSubview:viewController.view];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[viewController.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDone:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController]; [moviePlayerController play];
//play
}
return self;
}
答案 0 :(得分:0)
在ViewController.h中
MPMoviePlayerController *moviePlayerController;
在ViewController.m中
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"try" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 10, 320,300)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
moviePlayerController.controlStyle=MPMovieControlStyleEmbedded;
[moviePlayerController play];
}