Playing Video on iPhone Cocos2D-X

I also put a function to open URL there. Probably, it’s not the best place for it in VideoUtils and should be moved somewhere else :slight_smile:

Dmitry,

I have an error building the native code :frowning:

Compile++ thumb : cocos2d <= CCVideoUtilsJni.cpp
jni/…/…/…/cocos2dx/platform/android/jni/CCVideoUtilsJni.cpp: In function ‘void Java_org_cocos2dx_lib_Cocos2dxVideo_onVideoCompleted(JNIEnv**, _jobject**)’:
jni/…/…/…/cocos2dx/platform/android/jni/CCVideoUtilsJni.cpp:28: error: pointer to member type ’void (cocos2d::SelectorProtocol::)(cocos2d::CCNode**)‘incompatible with object type ’cocos2d::CCObject’
make:***** Error 1
Did you also encounter this ?
because to be honest at this moment I don’t understand what the cocos2d::CCNode** withObject parameter should be :"> )

Just replace SelectorProtocol with CCObject (the latest version of cocos2d-x removed SelectorProtocol). I have already updated it in my source code.
withObject - is just a parameter that you can pass in your callback function, and it can be NULL. I used it in case if I had a window with button to play video, then I passed this window in callback and in the callback I close that window.

Maybe this is just not my day,
The only place where I found and replace SelectorProtocol was in CCVideoUtils_ios.mm
and I still have the problem

(I’m using cocos2d-1.0.1-x-0.11.0)

What the compiler says now?

same error
(even if I’ve deleted the android\obj dir to force a overall rebuild)

Ah, then I was just using more recent version of cocos2d-x from GitHub where SelectorProtocol is already removed.

Then your case you need to change CCObject back to SelectorProtocol (for target parameter)

Switching to SelectorProtocol solved the compilation
I think I’ll leave it as it for today and try to call playVideo into the project tomorrow.

Thanks Dmitry, I should mail you a six pack :slight_smile:

I’ve encountered a problem while testing today.
Firstly I’ve played a .3pg H263 352x288 it played OK (video&audio) on emulator but I got only audio while testing on my Samsung Galaxy S phone.
Then I’ve played a .mp4 H264 640x344 and both on emulator and device I got only audio playing.
(on both emulator and phone I got android 2.3.3)

First attempt to solve it by setting the layout params to FILL_PARENT did not work.
I’ll look more into it.

To Dmitry Matyukhin.

I’m using your approach to interact with MPMoviePlayerController from C++. Thank you for it!

I’ve got a problem with rotation of device. It seems that video orientation is fixed with this line from your code:

[player2.view setTransform:CGAffineTransformMakeRotation(M_PI_2)];

But I need the video to rotate as the whole application does:

// RootViewController.mm
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}

How can I achieve required behavior?