Attach .mov in CCNode, not on OpenGLView

Forums Programming cocos2d support (graphics engine) Attach .mov in CCNode, not on OpenGLView

This topic contains 15 replies, has 12 voices, and was last updated by  firstpixel 2 years, 7 months ago.

Viewing 16 posts - 1 through 16 (of 16 total)
Author Posts
Author Posts
September 1, 2010 at 6:39 pm #224452

user0001
@user0001

Hi,

is there a way to attach a movie (MPMoviePlayer) within a cocos2d node vs. on top in its OpenGLView? if i attach the MPMoviePlayer like so:

[[[CCDirector sharedDirector] openGLView] addSubview:myMPMoviePlayer];

i have layering (z depth) problems between my video and other CCSprites and also the video doesn’t animate along with my scene transitions, since its sitting on top of everything.

thanks!

Jer

September 2, 2010 at 12:11 am #296581

wiegerthefarmer
@wiegerthefarmer

If you find out about this, please let me know. I want to use a video file as the background of a game. Think Rayman’s Raving Rabbids the plunger levels…

September 2, 2010 at 1:07 am #296582

hm50
Participant
@hm50

I to am using an MPMoviePlayer in a cocos app and was considering how to implement it in a fashion similar to yours. I haven’t read much on it yet, but would the CCUIViewWrapper classes help here?

September 2, 2010 at 1:20 am #296583

wiegerthefarmer
@wiegerthefarmer

Looks like it might work. If I get around to my other side projects, I’ll try it out!

September 2, 2010 at 4:48 am #296584

user0001
@user0001

I’ve tried CCUIViewWrapper and it just uses the same implementation: attaching the movie to the openGLView of [CCDirector sharedDirector].

I’m still trying to find a way of integrating an .mov into a CCNode object.

Has anyone done this? Is this even possible?

Thanks!

September 2, 2010 at 1:30 pm #296585

ascorbin
Participant
@ascorbin

I succesfully arranged a transparent CocosLayer on top of a MoviePlayerLayer in cocos 99.5.

1. change EAGLView pixelFormat to kEAGLColorFormatRGBA8 for transparency.

2. in CCDirerector -(void) setGLDefaultValues set glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

3. in the delegate:

[viewController.view addSubview:glView];

[viewController.view addSubview:moviePlayer.view];

[viewController.view sendSubviewToBack:moviePlayer.view];

so you have your mov playing in the background and all normal cocos stuff on top.

greetings ascorbin

September 2, 2010 at 1:33 pm #296586

ascorbin
Participant
@ascorbin
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// Init the window
window = UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds;

// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];

CCDirector *director = [CCDirector sharedDirector];

// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;

//
// Create the EAGLView manually
// 1. Create a RGB565 format. Alternative: RGBA8
// 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
//
//
EAGLView *glView = [EAGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
preserveBackbuffer:NO];

// attach the openglView to the director
[director setOpenGLView:glView];

// To enable Hi-Red mode (iPhone4)
// [director setContentScaleFactor:2];

//
// VERY IMPORTANT:
// If the rotation is going to be controlled by a UIViewController
// then the device orientation should be "Portrait".
//
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeLeft];
#endif

[director setAnimationInterval:1.0/60];
[director setDisplayFPS:NO];

// make the OpenGLView a child of the view controller
//[viewController setView:glView];

[viewController.view addSubview:glView];

// make the View Controller a child of the main window
[window addSubview: viewController.view];

[window makeKeyAndVisible];

NSURL *url = [NSURL fileURLWithPath:NSBundle mainBundle] pathForResource:@"Schwarzweisskratzer" ofType:@"mov";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];

if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = YES;
moviePlayer.repeatMode = MPMovieRepeatModeOne;
//[moviePlayer setFullscreen:YES animated:YES];
CGRect win = [[UIScreen mainScreen] bounds];
//[moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];

moviePlayer.view.frame = CGRectMake(0, 0, win.size.height, win.size.width);
[viewController.view addSubview:moviePlayer.view];
[viewController.view sendSubviewToBack:moviePlayer.view];
printf("nnsoson");
} else {
// Use the old 2.0 style API
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
}

// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

// Run the intro Scene
CCDirector sharedDirector] runWithScene: [overlay scene;
}

& dont forget glClearColor(0.0f, 0.0f, 0.0f, 0.0f); in CCDirector.m

September 6, 2010 at 2:58 pm #296587

wiegerthefarmer
@wiegerthefarmer

Fraking sweet @ascorbin !!!! Looking forward to trying this out!

December 18, 2010 at 6:25 pm #296588

slycrel
Participant
@slycrel

I was having some trouble with getting this working. I found in another thread that you have to set

glView.opaque = NO;

in order for your movie view to show under the main CCDirector EAGLView (in addition to changing the default clear in CCDirector to be 0.0f alpha instead of 1.0f). Not sure if this is a recent change or not, but otherwise this didn’t work for me.

edit: Did a decent write-up at stack overflow for my personal future reference as well as I hadn’t seen a more beginner friendly guide around.

December 19, 2010 at 11:07 am #296589

cublah
Participant
@cublah

There seems to be a slight problem with this when you enable Retina Mode. It creates a surface of 1920×1280 instead of 960×640

December 23, 2010 at 5:36 am #296590

antoine anim
Participant
@antoine-anim

thanks slycrel, i test your code, it work fine on the delegate but i struggle to make the movie work in the background on a different scene rather than the delegate. some hint will be appreciate.

antoine

January 12, 2011 at 5:19 am #296591

morfest
Participant
@morfest

Thank you ascorbin for solution.

it work for not ratina display

but run in retina display mode …. everything wrong!

i don’t know for this problem , please help me again

thank you

February 9, 2011 at 10:04 am #296592

kuldeep.rajput
@kuldeeprajput

how to play video in background this code is giving so many errors? any sample project for it

June 6, 2011 at 8:58 pm #296593

Stepan Generalov
Moderator
@ipsi

Background video playback is planned for CCVideoPlayer: https://github.com/cocos2d/cocos2d-iphone-extensions/issues/5

CCVideoPlayer is compatible with cocos2d-iphone release-1.0.0-rc3 and have test/demo within cocos2d-iphone-extensions repo.

Compatible devices: iPad/iPhone/Retina/Mac.

If anyone would like to add background playback to it – send me a pull request, please.

Thanks!

June 6, 2011 at 11:42 pm #296594

zaaroth
Participant
@zaaroth

How is the FPS for your implementation Stepan? Wrapping the UIKit controller with cocos2d is likely to drop the FPS to a quarter or less on older devices.

September 2, 2011 at 6:35 pm #296595

firstpixel
Participant
@firstpixel

Is there anyway to keep cocos2d running on top of the video? Trying it, works fine on 3gs and ipad, but in retina display , the video is ok, but cocos2d is off set.

Does anyone know how to fix it? Tried the extension also, but it seems to stop cocos2d to work, I want my game to keep running and have the video as background.

Viewing 16 posts - 1 through 16 (of 16 total)

You must be logged in to reply to this topic.