cocos js android 添加视频循环播放

Cocos2dxVideoView.java:
private boolean isLoop = false;
//添加方法
public void setLooping(boolean loop) {
    this.isLoop = loop;
    if(mMediaPlayer!=null){
    	mMediaPlayer.setLooping(loop);
    }
}
//修改
public void start() {
    if (isInPlaybackState()) {
        if(this.isLoop){ //播放的时候设置为循环播放
        	this.setLooping(true);
        }
        mMediaPlayer.start();
        mCurrentState = STATE_PLAYING;
        if (mOnVideoEventListener != null) {
            mOnVideoEventListener.onVideoEvent(mViewTag, EVENT_PLAYING);
        }
    }
    mTargetState = STATE_PLAYING;
}


Cocos2dxVideoHelper.java:
private final static int VideoTaskSetLooping = 13;

@Override
public void handleMessage(Message msg) {
	case VideoTaskSetLooping:{
        //_setLooping
        Cocos2dxVideoHelper helper = mReference.get();
        if(msg.arg2 == 0){
            helper._setVideoLooping(msg.arg1,false);
        }else{
            helper._setVideoLooping(msg.arg1,true);
        }
		break;
    }
}
public static void setVideoLooping(int index,int isLoop) {
    Message msg = new Message();
    msg.what = VideoTaskSetLooping;
    msg.arg1 = index;
    msg.arg2 = isLoop;
    mVideoHandler.sendMessage(msg);
}
    
public void _setVideoLooping(int index,boolean isLoop) {
    Cocos2dxVideoView view = sVideoViews.get(index);
    if(view!=null){
    view.setLooping(isLoop);
    }
}
	
	
C:\Cocos\frameworks\cocos2d-x-3.9\cocos\ui\UIVideoPlayer.h
virtual void setVideoLooping(bool isLoop);

C:\Cocos\frameworks\cocos2d-x-3.9\cocos\ui\UIVideoPlayer-android.cpp
void VideoPlayer::setVideoLooping(bool isLoop)
{
	if (isLoop) {
		setVideoLoopingJNI(_videoPlayerIndex, 1);
	}
	else {
		setVideoLoopingJNI(_videoPlayerIndex, 0);
	}
}
void setVideoLoopingJNI(int index, int isLoop) 
{
	JniMethodInfo t;
	if (JniHelper::getStaticMethodInfo(t, CLASS_NAME, "setVideoLooping", "(II)V")) {
		t.env->CallStaticVoidMethod(t.classID, t.methodID, index, isLoop);

		t.env->DeleteLocalRef(t.classID);
	}
}

C:\Cocos\frameworks\cocos2d-x-3.9\cocos\scripting\js-bindings\auto\jsb_cocos2dx_experimental_video_auto.hpp
bool js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping(JSContext *cx, uint32_t argc, jsval *vp);

C:\Cocos\frameworks\cocos2d-x-3.9\cocos\scripting\js-bindings\auto\jsb_cocos2dx_experimental_video_auto.cpp
bool js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping(JSContext *cx, uint32_t argc, jsval *vp)
{
	JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
	bool ok = true;
	JS::RootedObject obj(cx, args.thisv().toObjectOrNull());
	js_proxy_t *proxy = jsb_get_js_proxy(obj);
	cocos2d::experimental::ui::VideoPlayer* cobj = (cocos2d::experimental::ui::VideoPlayer *)(proxy ? proxy->ptr : NULL);
	JSB_PRECONDITION2(cobj, cx, false, "js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping : Invalid Native Object");
	if (argc == 1) {
		bool arg0;
		arg0 = JS::ToBoolean(args.get(0));
		JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping : Error processing arguments");
		cobj->setVideoLooping(arg0);
		args.rval().setUndefined();
		return true;
	}

	JS_ReportError(cx, "js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping : wrong number of arguments: %d, was expecting %d", argc, 1);
	return false;
}
static JSFunctionSpec funcs[] = {    
//注册方法
		JS_FN("setVideoLooping", js_cocos2dx_experimental_video_VideoPlayer_setVideoLooping, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE),
        JS_FS_END
};
	
	

 

你可能感兴趣的:(cocos,android)