Use QTMovieView in Cocos2D Mac?
Is it possible? I guess it is, but I can't figure it out.
So, the code for the movie thus far:
shrigString = [[NSBundle mainBundle] pathForResource:@"shrig_h264_720p" ofType:@"mov"]; shrigURL = [NSURL fileURLWithPath:shrigString]; //shrigMovie = [QTMovie movieWithFile:@"shrig_h264_720p.mov" error:nil]; shrigMovie = [QTMovie movieWithURL:shrigURL error:nil]; shrigMovieView = [QTMovieLayer layerWithMovie:shrigMovie];
[[[[CCDirectorMac sharedDirector] openGLView] window] addChildWindow:shrigWindow ordered:NSWindowAbove];
[shrigWindow setContentView:shrigNSView];
[shrigNSView setLayer:shrigMovieView];
shrigMovieView.frame = CGRectMake(size.width /2, size.height /2, 1024, 576);
[shrigMovie autoplay];
[shrigMovie play];
NSLog(@"shrigMovie: %@", shrigMovie);
NSLog(@"shrigMovie is: %@", QTStringFromTime([shrigMovie currentTime]));
However, I can't figure out ho开发者_如何学Pythonw to ad that to my scene. This is Cocos2D for Mac btw.
In the console:
shrigMovie is: 0:00:00:00.00/2500 So I guess it's loading ok, but simply not displaying?
Any ideas would be hugely appreciated.
Thanks.
I ran into the same problem and spent quite a while trying to figure out how to solve it using QTMovie in combination with cocos2D. Eventually I gave up and started looking if there was a good existing solution to this. And voilà, I found VideoPlayer. Very easy to use and very lightweight, you can find it on https://github.com/psineur/CCVideoPlayer. Just be sure to copy only the necessary VideoPlayer-folder from the zip-file and don't forget the CustomVideoView.nib in the Resources folder. Add those to some lib-folder within your project, then you can start playing Video-files using those two lines:
[VideoPlayer setDelegate:self];
[VideoPlayer playMovieWithFile:@"intro.mov"];
You can then add the following delegate methods to your class
- (void) moviePlaybackFinished
{
}
- (void) movieStartsPlaying
{
}
Got it working in less than 10 minutes :)
Cheers
精彩评论