Biraj
October 14, 2013, 9:37am
#1
I am developing simple cocos2d-x game. I have to play video in half screen.But video is always plays in full screen even I have specified size to (200X200) and specifies position to (0,0).
Look at my code
HelloWorld.cpp
CCScene* HelloWorld::scene()
{
// 'scene' is an autorelease object
CCScene *scene = CCScene::create();
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
// add layer as a child to scene
layer->setContentSize(CCSizeMake(200,200));
layer->setPosition(ccp(0,0));
scene->addChild(layer);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
WrapperClass::getShared()->playVideo("sampleVideo");
return true;
}
I want to play video in left-top corner of screen in fixed size block of (200X200).But not success can anybody help me out?
cant help u much without knowing whats happening in WrapperClass
Biraj
October 14, 2013, 10:40am
#3
//
// WrapperClass.h
// Farmer
//
//
//
#ifndef __Farmer__WrapperClass__
#define __Farmer__WrapperClass__
#include "cocos2d.h"
#include "CCApplication.h"
using namespace cocos2d;
class WrapperClass : public cocos2d::CCObject {
public:
void playVideo(const char *vidPath);
static WrapperClass *getShared();
};
#endif /* defined(__Farmer__WrapperClass__) */
//
// WrapperClass.cpp
// Farmer
//
//
//
//
#include "WrapperClass.h"
#include "AudioManager.h"
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
#include "iOSWrapper.h"
#include "cocos2d.h"
#endif
static WrapperClass *instance = NULL;
void WrapperClass::playVideo(const char *vidPath) {
AudioManager::sharedManager()->stopBG();
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
iOSWrapper::getShared()->playVideo(vidPath);
#elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
CCApplication::sharedApplication()->playVideo();
#endif
}
WrapperClass *WrapperClass::getShared() {
if (!instance) {
instance = new WrapperClass();
}
return instance;
}
CCApplication.cpp
#include "jni/JniHelper.h"
#include "jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
#include "CCApplication.h"
#include "CCDirector.h"
#include "CCEGLView.h"
#include
#include
#include
#define LOG_TAG "CCApplication_android Debug"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
NS_CC_BEGIN
// sharedApplication pointer
CCApplication * CCApplication::sm_pSharedApplication = 0;
CCApplication::CCApplication()
{
CCAssert(! sm_pSharedApplication, "");
sm_pSharedApplication = this;
}
CCApplication::~CCApplication()
{
CCAssert(this == sm_pSharedApplication, "");
sm_pSharedApplication = NULL;
}
int CCApplication::run()
{
// Initialize instance and cocos2d.
if (! applicationDidFinishLaunching())
{
return 0;
}
return -1;
}
void CCApplication::setAnimationInterval(double interval)
{
JniMethodInfo methodInfo;
if (! JniHelper::getStaticMethodInfo(methodInfo, "org/cocos2dx/lib/Cocos2dxRenderer", "setAnimationInterval",
"(D)V"))
{
CCLOG("%s %d: error to get methodInfo", __FILE__, __LINE__);
}
else
{
methodInfo.env->CallStaticVoidMethod(methodInfo.classID, methodInfo.methodID, interval);
}
}
//////////////////////////////////////////////////////////////////////////
// static member function
//////////////////////////////////////////////////////////////////////////
CCApplication* CCApplication::sharedApplication()
{
CCAssert(sm_pSharedApplication, "");
return sm_pSharedApplication;
}
ccLanguageType CCApplication::getCurrentLanguage()
{
std::string languageName = getCurrentLanguageJNI();
const char* pLanguageName = languageName.c_str();
ccLanguageType ret = kLanguageEnglish;
if (0 == strcmp("zh", pLanguageName))
{
ret = kLanguageChinese;
}
else if (0 == strcmp("en", pLanguageName))
{
ret = kLanguageEnglish;
}
else if (0 == strcmp("fr", pLanguageName))
{
ret = kLanguageFrench;
}
else if (0 == strcmp("it", pLanguageName))
{
ret = kLanguageItalian;
}
else if (0 == strcmp("de", pLanguageName))
{
ret = kLanguageGerman;
}
else if (0 == strcmp("es", pLanguageName))
{
ret = kLanguageSpanish;
}
else if (0 == strcmp("ru", pLanguageName))
{
ret = kLanguageRussian;
}
else if (0 == strcmp("ko", pLanguageName))
{
ret = kLanguageKorean;
}
else if (0 == strcmp("ja", pLanguageName))
{
ret = kLanguageJapanese;
}
else if (0 == strcmp("hu", pLanguageName))
{
ret = kLanguageHungarian;
}
else if (0 == strcmp("pt", pLanguageName))
{
ret = kLanguagePortuguese;
}
else if (0 == strcmp("ar", pLanguageName))
{
ret = kLanguageArabic;
}
return ret;
}
TargetPlatform CCApplication::getTargetPlatform()
{
return kTargetAndroid;
}
void CCApplication::playVideo(){
JniMethodInfo minfo;
if(JniHelper::getStaticMethodInfo(minfo,
"in/gethugames/VideoPlayer",
//"com/smaat/dropinthehole",
"playVideo",
"(Ljava/lang/String;)V"))
{
jstring StringArg1 = minfo.env->NewStringUTF("sample.mov");
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, StringArg1);
minfo.env->DeleteLocalRef(StringArg1);
minfo.env->DeleteLocalRef(minfo.classID);
}
}
void CCApplication::openURL(const char *urlString){
JniMethodInfo minfo;
if(JniHelper::getStaticMethodInfo(minfo,
"com/smaat/dropinthehole",
"openURL",
"(Ljava/lang/String;)V"))
{
jstring StringArg1 = minfo.env->NewStringUTF(urlString);
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, StringArg1);
minfo.env->DeleteLocalRef(StringArg1);
minfo.env->DeleteLocalRef(minfo.classID);
}
}
*CCApplication.h*
#ifndef __CC_APPLICATION_ANDROID_H__
#define __CC_APPLICATION_ANDROID_H__
#include "platform/CCCommon.h"
#include "platform/CCApplicationProtocol.h"
NS_CC_BEGIN
class CCRect;
class CC_DLL CCApplication : public CCApplicationProtocol
{
public:
CCApplication();
virtual ~CCApplication();
/**
@brief Callback by CCDirector to limit FPS.
@interval The time, expressed in seconds, between current frame and next.
*/
void setAnimationInterval(double interval);
/**
@brief Run the message loop.
*/
int run();
/**
@brief Get current application instance.
@return Current application instance pointer.
*/
static CCApplication* sharedApplication();
/**
@brief Get current language config
@return Current language config
*/
virtual ccLanguageType getCurrentLanguage();
/**
@brief Get target platform
*/
virtual TargetPlatform getTargetPlatform();
void playVideo();
void openURL(const char *urlString);
protected:
static CCApplication * sm_pSharedApplication;
};
NS_CC_END
#endif // __CC_APPLICATION_ANDROID_H__
NS_CC_END
It depends upon the layout you have used to play your video file in android xml and java code.
Can you post Java and XML code here.
Biraj
October 16, 2013, 6:33am
#5
Thanks man I got the problem there was match_parent in my layout.Now it works nice.