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
};
	
	

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值