From 32b4f63d45893372c9904f99098c9436cc07b7c9 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 15 Aug 2016 01:11:32 +0800 Subject: [PATCH 1/8] Fix Creator module memory not controlled by cpp --- native/tools/tojs/creator.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/tools/tojs/creator.ini b/native/tools/tojs/creator.ini index d57a7a029e..97674c8da2 100755 --- a/native/tools/tojs/creator.ini +++ b/native/tools/tojs/creator.ini @@ -63,4 +63,4 @@ base_classes_to_skip = Ref abstract_classes = Helper LayoutManager AbstractCheckButton # Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'. -script_control_cpp = yes +script_control_cpp = no From 2a903b9ce2192962654948035d4045b545585d41 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Mon, 15 Aug 2016 01:17:57 +0800 Subject: [PATCH 2/8] Gen autobindings for v1.2 branch --- native/.travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/.travis.yml b/native/.travis.yml index 2cde41c24c..8bb07b54d1 100644 --- a/native/.travis.yml +++ b/native/.travis.yml @@ -8,7 +8,7 @@ before_install: - tools/travis-scripts/before-install.sh branches: only: - - develop + - v1.2 env: global: - secure: bUrk522Qw5Mc3SfDXHZtJ/aF9QbLXYDnUVSOJXt1wUB1d8xAQphTcZ1ARNYu7I5m3ZXqRfzTS4POOT58qeS3sYPpJ8urWW18hgX3I/dmsL1WJXmwnOV+0J3xLt6AT3ttqj7/emaf0xxuBvZ0szyRz0rU4wprtWftWMFiUrsF8G1an2Qa/g/f5LhilnDiKAqFdHMkn0ogaggL0PbgliHeHo7SEOfSF2gQaSIBta7jzE/BEZZ3R4AuReB3oNDwxr+1E4BpPaGO1lMLzdr8MAjWBGVLBRlpVDihgFTTmdka8UYasjEWDs6GbSjJRsTZQkluOo+1UylSiLn5o1tnWMqINo5DDaayBSKWRV/x+Sx+KMG221BwHLGFHrhEm8Jwc3g5IBiFrc9Xn/PAoCL3Zi/m0m8Y/TVIlA2nWuU0jeMZYXOb0ALCplAQMrG/Yt7euzgSjZ9iPvO7HO8BkaRkUxafcp6svWyMedNeDczG6liLSquJak+XIbOpWCOW+KVxc2S2Unz37MSOQR/aB9dJ8fKI/4e3LCdYrSKW9MSKAz9BSYA2IK2F8Fgr6zY3IPTANQCi6o8i/N54wsmpY17uvzqNDGuag5m/FkNpFWVQUy/TdONanXV6m1jvREaxtDHucSnP3olmvx6pi1awRspDfRmcILK08yvul+yLol0nQwenlx0= From 9da0205b308c21b6d25121f6dae2be20fc54c17f Mon Sep 17 00:00:00 2001 From: CocosRobot Date: Sun, 14 Aug 2016 17:25:41 +0000 Subject: [PATCH 3/8] [ci skip][AUTO]: updating jsbinding automatically --- .../js-bindings/auto/jsb_creator_auto.cpp | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp index 4f75509b9f..5f7b3bad27 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_creator_auto.cpp @@ -8,6 +8,8 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedValue initializing(cx); bool isNewValid = true; + JS::RootedObject global(cx, ScriptingCore::getInstance()->getGlobalObject()); + isNewValid = JS_GetProperty(cx, global, "initializing", &initializing) && initializing.toBoolean(); if (isNewValid) { TypeTest t; @@ -22,13 +24,11 @@ static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::RootedObject parent(cx, typeClass->parentProto.ref()); JS::RootedObject _tmp(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); - T* cobj = new T(); - js_proxy_t *pp = jsb_new_proxy(cobj, _tmp); - AddObjectRoot(cx, &pp->obj); args.rval().set(OBJECT_TO_JSVAL(_tmp)); return true; } + JS_ReportError(cx, "Constructor for the requested class is not available, please refer to the API reference."); return false; } @@ -784,6 +784,10 @@ bool js_creator_Scale9SpriteV2_constructor(JSContext *cx, uint32_t argc, jsval * JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; creator::Scale9SpriteV2* cobj = new (std::nothrow) creator::Scale9SpriteV2(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); @@ -796,7 +800,8 @@ bool js_creator_Scale9SpriteV2_constructor(JSContext *cx, uint32_t argc, jsval * JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object - jsb_new_proxy(cobj, obj); + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "creator::Scale9SpriteV2"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; @@ -805,7 +810,11 @@ bool js_creator_Scale9SpriteV2_constructor(JSContext *cx, uint32_t argc, jsval * JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); creator::Scale9SpriteV2 *nobj = new (std::nothrow) creator::Scale9SpriteV2(); + if (nobj) { + nobj->autorelease(); + } js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "creator::Scale9SpriteV2"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); @@ -817,18 +826,6 @@ extern JSObject *jsb_cocos2d_Node_prototype; void js_creator_Scale9SpriteV2_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (Scale9SpriteV2)", obj); - JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS::RootedObject jsobj(cx, obj); - auto proxy = jsb_get_js_proxy(jsobj); - if (proxy) { - creator::Scale9SpriteV2 *nobj = static_cast(proxy->ptr); - - if (nobj) { - jsb_remove_proxy(proxy); - nobj->release(); - } - else jsb_remove_proxy(proxy); - } } void js_register_creator_Scale9SpriteV2(JSContext *cx, JS::HandleObject global) { @@ -1595,6 +1592,10 @@ bool js_creator_GraphicsNode_constructor(JSContext *cx, uint32_t argc, jsval *vp JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; creator::GraphicsNode* cobj = new (std::nothrow) creator::GraphicsNode(); + cocos2d::Ref *_ccobj = dynamic_cast(cobj); + if (_ccobj) { + _ccobj->autorelease(); + } TypeTest t; js_type_class_t *typeClass = nullptr; std::string typeName = t.s_name(); @@ -1607,7 +1608,8 @@ bool js_creator_GraphicsNode_constructor(JSContext *cx, uint32_t argc, jsval *vp JS::RootedObject obj(cx, JS_NewObject(cx, typeClass->jsclass, proto, parent)); args.rval().set(OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object - jsb_new_proxy(cobj, obj); + js_proxy_t* p = jsb_new_proxy(cobj, obj); + AddNamedObjectRoot(cx, &p->obj, "creator::GraphicsNode"); if (JS_HasProperty(cx, obj, "_ctor", &ok) && ok) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); return true; @@ -1616,7 +1618,11 @@ bool js_creator_GraphicsNode_constructor(JSContext *cx, uint32_t argc, jsval *vp JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); creator::GraphicsNode *nobj = new (std::nothrow) creator::GraphicsNode(); + if (nobj) { + nobj->autorelease(); + } js_proxy_t* p = jsb_new_proxy(nobj, obj); + AddNamedObjectRoot(cx, &p->obj, "creator::GraphicsNode"); bool isFound = false; if (JS_HasProperty(cx, obj, "_ctor", &isFound) && isFound) ScriptingCore::getInstance()->executeFunctionWithOwner(OBJECT_TO_JSVAL(obj), "_ctor", args); @@ -1628,18 +1634,6 @@ extern JSObject *jsb_cocos2d_Node_prototype; void js_creator_GraphicsNode_finalize(JSFreeOp *fop, JSObject *obj) { CCLOGINFO("jsbindings: finalizing JS object %p (GraphicsNode)", obj); - JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); - JS::RootedObject jsobj(cx, obj); - auto proxy = jsb_get_js_proxy(jsobj); - if (proxy) { - creator::GraphicsNode *nobj = static_cast(proxy->ptr); - - if (nobj) { - jsb_remove_proxy(proxy); - nobj->release(); - } - else jsb_remove_proxy(proxy); - } } void js_register_creator_GraphicsNode(JSContext *cx, JS::HandleObject global) { From b7c07b6b6c0b78ab1bbfa8cb4888e91ce612b41e Mon Sep 17 00:00:00 2001 From: 2youyouo2 <501251991@qq.com> Date: Mon, 15 Aug 2016 12:01:57 +0800 Subject: [PATCH 4/8] fixed graphics arc --- native/cocos/editor-support/creator/CCGraphicsNode.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/cocos/editor-support/creator/CCGraphicsNode.cpp b/native/cocos/editor-support/creator/CCGraphicsNode.cpp index 3647390519..c6606ed4eb 100644 --- a/native/cocos/editor-support/creator/CCGraphicsNode.cpp +++ b/native/cocos/editor-support/creator/CCGraphicsNode.cpp @@ -214,7 +214,7 @@ void GraphicsNode::arc(float cx, float cy, float r, float startAngle, float endA // Clamp angles da = endAngle - startAngle; - if (!counterclockwise) { + if (counterclockwise) { if (absf(da) >= PI_2) { da = PI_2; } else { @@ -233,7 +233,7 @@ void GraphicsNode::arc(float cx, float cy, float r, float startAngle, float endA hda = (da / (float)ndivs) / 2.0f; kappa = absf(4.0f / 3.0f * (1.0f - cosf(hda)) / sinf(hda)); - if (counterclockwise) { + if (!counterclockwise) { kappa = -kappa; } From 15515c3d2de4a8398a1ce5ec57349735a2f96de8 Mon Sep 17 00:00:00 2001 From: "yanli.huang" Date: Tue, 16 Aug 2016 11:48:52 +0800 Subject: [PATCH 5/8] =?UTF-8?q?update=20cocos2d-console=20commit=EF=BC=9A?= =?UTF-8?q?=20add=20--env=20param=20to=20cocos=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- native/tools/cocos2d-console | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/tools/cocos2d-console b/native/tools/cocos2d-console index 7164d48421..fdad71adcf 160000 --- a/native/tools/cocos2d-console +++ b/native/tools/cocos2d-console @@ -1 +1 @@ -Subproject commit 7164d484212b95578e9827cae595cb2590d648a7 +Subproject commit fdad71adcf580741398d3ef93ac2f835023ef06c From 062169358d322dc53653dba290864cb41ceaa318 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 15 Aug 2016 19:55:13 +0800 Subject: [PATCH 6/8] add currentTime and duration in iOS --- native/cocos/ui/UIVideoPlayer-ios.mm | 28 ++++++++++++++++++++++++++++ native/cocos/ui/UIVideoPlayer.h | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/native/cocos/ui/UIVideoPlayer-ios.mm b/native/cocos/ui/UIVideoPlayer-ios.mm index 01417589f8..fb3dd9e931 100644 --- a/native/cocos/ui/UIVideoPlayer-ios.mm +++ b/native/cocos/ui/UIVideoPlayer-ios.mm @@ -45,6 +45,8 @@ using namespace cocos2d::experimental::ui; - (void) resume; - (void) stop; - (void) seekTo:(float) sec; +- (float) currentTime; +- (float) duration; - (void) setVisible:(BOOL) visible; - (void) setKeepRatioEnabled:(bool) enabled; - (void) setFullScreenEnabled:(bool) enabled; @@ -207,6 +209,22 @@ using namespace cocos2d::experimental::ui; } } +-(float) currentTime +{ + if (self.moviePlayer != NULL) { + return [self.moviePlayer currentPlaybackTime]; + } + return -1; +} + +-(float) duration +{ + if (self.moviePlayer != NULL) { + return [self.moviePlayer duration]; + } + return -1; +} + -(void) setVisible:(BOOL)visible { if (self.moviePlayer != NULL) { @@ -409,6 +427,16 @@ void VideoPlayer::seekTo(float sec) } } +float VideoPlayer::currentTime()const +{ + return [((UIVideoViewWrapperIos*)_videoView) currentTime]; +} + +float VideoPlayer::duration()const +{ + return [((UIVideoViewWrapperIos*)_videoView) duration]; +} + bool VideoPlayer::isPlaying() const { return _isPlaying; diff --git a/native/cocos/ui/UIVideoPlayer.h b/native/cocos/ui/UIVideoPlayer.h index 79ebddaa2e..9f672c0fab 100644 --- a/native/cocos/ui/UIVideoPlayer.h +++ b/native/cocos/ui/UIVideoPlayer.h @@ -122,6 +122,13 @@ namespace experimental{ */ virtual void seekTo(float sec); + /** + * Get the current play time, measure in seconds. + */ + float currentTime()const; + + float duration() const; + /** * Checks whether the VideoPlayer is playing. * From 860428af73c36fe1ebba2744ddd310026a321802 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 16 Aug 2016 12:01:23 +0800 Subject: [PATCH 7/8] add android support --- .../org/cocos2dx/lib/Cocos2dxVideoHelper.java | 66 ++++++++++++++++++- ...sb_cocos2dx_experimental_video_auto_api.js | 20 ++++++ .../jsb_cocos2dx_experimental_video_auto.cpp | 38 +++++++++++ .../jsb_cocos2dx_experimental_video_auto.hpp | 2 + native/cocos/ui/UIVideoPlayer-android.cpp | 10 +++ 5 files changed, 135 insertions(+), 1 deletion(-) diff --git a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java index cacebbd246..fda28608c7 100644 --- a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java +++ b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java @@ -26,24 +26,34 @@ package org.cocos2dx.lib; import android.graphics.Rect; import android.os.Handler; +import android.os.Looper; import android.os.Message; +import android.util.Log; import android.util.SparseArray; import android.view.View; import android.widget.FrameLayout; +import android.widget.VideoView; import org.cocos2dx.lib.Cocos2dxVideoView.OnVideoEventListener; import java.lang.ref.WeakReference; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; public class Cocos2dxVideoHelper { static VideoHandler sVideoHandler = null; - private SparseArray mVideoViews = null; + private static SparseArray mVideoViews = null; + private static Handler sHandler = null; + Cocos2dxVideoHelper() { sVideoHandler = new VideoHandler(this); mVideoViews = new SparseArray(); + sHandler = new Handler(Looper.myLooper()); } private static int videoTag = 0; @@ -60,6 +70,8 @@ public class Cocos2dxVideoHelper { private final static int VideoTaskRestart = 10; private final static int VideoTaskKeepRatio = 11; private final static int VideoTaskFullScreen = 12; + private final static int VideoTaskCurrentTime = 13; + private final static int VideoTaskDuration = 14; final static int KeyEventBack = 1000; static class VideoHandler extends Handler{ @@ -370,6 +382,58 @@ public class Cocos2dxVideoHelper { } } + + public static T callInMainThread(Callable call) throws ExecutionException, InterruptedException { + FutureTask task = new FutureTask(call); + sHandler.post(task); + return task.get(); + } + + public static float getCurrentTime(final int index) { + Callable callable = new Callable() { + @Override + public Float call() throws Exception { + Cocos2dxVideoView viedo = mVideoViews.get(index); + float currentPosition = -1; + if (viedo != null) { + currentPosition = viedo.getCurrentPosition() / 1000.0f; + } + return new Float(currentPosition); + } + }; + + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return -1; + } catch (InterruptedException e) { + return -1; + } + } + + public static float getDuration(final int index) { + Callable callable = new Callable() { + @Override + public Float call() throws Exception { + Cocos2dxVideoView viedo = mVideoViews.get(index); + float duration = -1; + if (viedo != null) { + duration = viedo.getDuration() / 1000.0f; + } + return new Float(duration); + } + }; + + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return -1; + } catch (InterruptedException e) { + return -1; + } + } + + public static void setVideoVisible(int index, boolean visible) { Message msg = Message.obtain(); msg.what = VideoTaskSetVisible; diff --git a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_experimental_video_auto_api.js b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_experimental_video_auto_api.js index 1751546076..670496d4b2 100644 --- a/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_experimental_video_auto_api.js +++ b/native/cocos/scripting/js-bindings/auto/api/jsb_cocos2dx_experimental_video_auto_api.js @@ -46,6 +46,16 @@ bool { }, +/** + * @method currentTime + * @return {float} + */ +currentTime : function ( +) +{ + return 0; +}, + /** * @method stop */ @@ -114,6 +124,16 @@ isFullScreenEnabled : function ( return false; }, +/** + * @method duration + * @return {float} + */ +duration : function ( +) +{ + return 0; +}, + /** * @method isPlaying * @return {bool} diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.cpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.cpp index 9b93d5ebe9..d1d629b6ae 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.cpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.cpp @@ -117,6 +117,24 @@ bool js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled(JSCont JS_ReportError(cx, "js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled : wrong number of arguments: %d, was expecting %d", argc, 1); return false; } +bool js_cocos2dx_experimental_video_VideoPlayer_currentTime(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + 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_currentTime : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->currentTime(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_experimental_video_VideoPlayer_currentTime : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_experimental_video_VideoPlayer_stop(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -249,6 +267,24 @@ bool js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled(JSContext *c JS_ReportError(cx, "js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled : wrong number of arguments: %d, was expecting %d", argc, 0); return false; } +bool js_cocos2dx_experimental_video_VideoPlayer_duration(JSContext *cx, uint32_t argc, jsval *vp) +{ + JS::CallArgs args = JS::CallArgsFromVp(argc, vp); + 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_duration : Invalid Native Object"); + if (argc == 0) { + double ret = cobj->duration(); + jsval jsret = JSVAL_NULL; + jsret = DOUBLE_TO_JSVAL(ret); + args.rval().set(jsret); + return true; + } + + JS_ReportError(cx, "js_cocos2dx_experimental_video_VideoPlayer_duration : wrong number of arguments: %d, was expecting %d", argc, 0); + return false; +} bool js_cocos2dx_experimental_video_VideoPlayer_isPlaying(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); @@ -363,6 +399,7 @@ void js_register_cocos2dx_experimental_video_VideoPlayer(JSContext *cx, JS::Hand JS_FN("getURL", js_cocos2dx_experimental_video_VideoPlayer_getURL, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("play", js_cocos2dx_experimental_video_VideoPlayer_play, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("currentTime", js_cocos2dx_experimental_video_VideoPlayer_currentTime, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("stop", js_cocos2dx_experimental_video_VideoPlayer_stop, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_setFullScreenEnabled, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("setFileName", js_cocos2dx_experimental_video_VideoPlayer_setFileName, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), @@ -370,6 +407,7 @@ void js_register_cocos2dx_experimental_video_VideoPlayer(JSContext *cx, JS::Hand JS_FN("isKeepAspectRatioEnabled", js_cocos2dx_experimental_video_VideoPlayer_isKeepAspectRatioEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("onPlayEvent", js_cocos2dx_experimental_video_VideoPlayer_onPlayEvent, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isFullScreenEnabled", js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), + JS_FN("duration", js_cocos2dx_experimental_video_VideoPlayer_duration, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("isPlaying", js_cocos2dx_experimental_video_VideoPlayer_isPlaying, 0, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FN("seekTo", js_cocos2dx_experimental_video_VideoPlayer_seekTo, 1, JSPROP_PERMANENT | JSPROP_ENUMERATE), JS_FS_END diff --git a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.hpp b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.hpp index 5e854598b2..0fd62dee36 100644 --- a/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.hpp +++ b/native/cocos/scripting/js-bindings/auto/jsb_cocos2dx_experimental_video_auto.hpp @@ -17,6 +17,7 @@ bool js_cocos2dx_experimental_video_VideoPlayer_getFileName(JSContext *cx, uint3 bool js_cocos2dx_experimental_video_VideoPlayer_getURL(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_play(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_setKeepAspectRatioEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_experimental_video_VideoPlayer_currentTime(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_stop(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_setFullScreenEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_setFileName(JSContext *cx, uint32_t argc, jsval *vp); @@ -24,6 +25,7 @@ bool js_cocos2dx_experimental_video_VideoPlayer_setURL(JSContext *cx, uint32_t a bool js_cocos2dx_experimental_video_VideoPlayer_isKeepAspectRatioEnabled(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_onPlayEvent(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_isFullScreenEnabled(JSContext *cx, uint32_t argc, jsval *vp); +bool js_cocos2dx_experimental_video_VideoPlayer_duration(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_isPlaying(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_seekTo(JSContext *cx, uint32_t argc, jsval *vp); bool js_cocos2dx_experimental_video_VideoPlayer_create(JSContext *cx, uint32_t argc, jsval *vp); diff --git a/native/cocos/ui/UIVideoPlayer-android.cpp b/native/cocos/ui/UIVideoPlayer-android.cpp index fc2cb72a0f..8db8dde37c 100644 --- a/native/cocos/ui/UIVideoPlayer-android.cpp +++ b/native/cocos/ui/UIVideoPlayer-android.cpp @@ -313,5 +313,15 @@ void executeVideoCallback(int index,int event) } } +float VideoPlayer::currentTime() const +{ + return JniHelper::callStaticFloatMethod(videoHelperClassName, "getCurrentTime", _videoPlayerIndex); +} + +float VideoPlayer::duration() const +{ + return JniHelper::callStaticFloatMethod(videoHelperClassName, "getDuration", _videoPlayerIndex); +} + #endif From c18fa069ffc3d044abc96694d70892e81a31d198 Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Tue, 16 Aug 2016 12:52:38 +0800 Subject: [PATCH 8/8] fix android isPlaying API --- .../org/cocos2dx/lib/Cocos2dxVideoHelper.java | 35 +++++++++++++------ native/cocos/ui/UIVideoPlayer-android.cpp | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java index fda28608c7..782e337778 100644 --- a/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java +++ b/native/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java @@ -28,17 +28,14 @@ import android.graphics.Rect; import android.os.Handler; import android.os.Looper; import android.os.Message; -import android.util.Log; import android.util.SparseArray; import android.view.View; import android.widget.FrameLayout; -import android.widget.VideoView; import org.cocos2dx.lib.Cocos2dxVideoView.OnVideoEventListener; import java.lang.ref.WeakReference; import java.util.concurrent.Callable; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; @@ -70,8 +67,6 @@ public class Cocos2dxVideoHelper { private final static int VideoTaskRestart = 10; private final static int VideoTaskKeepRatio = 11; private final static int VideoTaskFullScreen = 12; - private final static int VideoTaskCurrentTime = 13; - private final static int VideoTaskDuration = 14; final static int KeyEventBack = 1000; static class VideoHandler extends Handler{ @@ -393,10 +388,10 @@ public class Cocos2dxVideoHelper { Callable callable = new Callable() { @Override public Float call() throws Exception { - Cocos2dxVideoView viedo = mVideoViews.get(index); + Cocos2dxVideoView video = mVideoViews.get(index); float currentPosition = -1; - if (viedo != null) { - currentPosition = viedo.getCurrentPosition() / 1000.0f; + if (video != null) { + currentPosition = video.getCurrentPosition() / 1000.0f; } return new Float(currentPosition); } @@ -415,10 +410,10 @@ public class Cocos2dxVideoHelper { Callable callable = new Callable() { @Override public Float call() throws Exception { - Cocos2dxVideoView viedo = mVideoViews.get(index); + Cocos2dxVideoView video = mVideoViews.get(index); float duration = -1; - if (viedo != null) { - duration = viedo.getDuration() / 1000.0f; + if (video != null) { + duration = video.getDuration() / 1000.0f; } return new Float(duration); } @@ -433,6 +428,24 @@ public class Cocos2dxVideoHelper { } } + public static boolean isPlaying(final int index) { + Callable callable = new Callable() { + @Override + public Boolean call() throws Exception { + Cocos2dxVideoView video = mVideoViews.get(index); + return video != null && video.isPlaying(); + } + }; + + try { + return callInMainThread(callable); + } catch (ExecutionException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + public static void setVideoVisible(int index, boolean visible) { Message msg = Message.obtain(); diff --git a/native/cocos/ui/UIVideoPlayer-android.cpp b/native/cocos/ui/UIVideoPlayer-android.cpp index 8db8dde37c..4a8f866a2b 100644 --- a/native/cocos/ui/UIVideoPlayer-android.cpp +++ b/native/cocos/ui/UIVideoPlayer-android.cpp @@ -227,7 +227,7 @@ void VideoPlayer::seekTo(float sec) bool VideoPlayer::isPlaying() const { - return _isPlaying; + return JniHelper::callStaticBooleanMethod(videoHelperClassName, "isPlaying", _videoPlayerIndex); } void VideoPlayer::setVisible(bool visible)