diff --git a/cocos/scripting/js-bindings/script/ccui/jsb_ccui_create_apis.js b/cocos/scripting/js-bindings/script/ccui/jsb_ccui_create_apis.js index e444aa9ae0..c14f90fdad 100644 --- a/cocos/scripting/js-bindings/script/ccui/jsb_ccui_create_apis.js +++ b/cocos/scripting/js-bindings/script/ccui/jsb_ccui_create_apis.js @@ -136,15 +136,22 @@ ccui.RichElementCustomNode.prototype._ctor = function(tag, color, opacity, custo customNode !== undefined && this.init(tag, color, opacity, customNode); }; -ccui.WebView.prototype._ctor = function(url){ - this.init(); - url !== undefined && this.loadURL(url); -}; +if (ccui.WebView) +{ + ccui.WebView.prototype._ctor = function(url){ + this.init(); + url !== undefined && this.loadURL(url); + }; +} + +if (ccui.VideoPlayer) +{ + ccui.VideoPlayer.prototype._ctor = function(url){ + this.init(); + url !== undefined && this.setURL(url); + }; +} -ccui.VideoPlayer.prototype._ctor = function(url){ - this.init(); - url !== undefined && this.setURL(url); -}; cc.Scale9Sprite.prototype._ctor = function(file, rect, capInsets){ rect = rect || cc.rect(0, 0, 0, 0); diff --git a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js index 7fbc336f4d..6bc5ffa5d9 100644 --- a/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js +++ b/cocos/scripting/js-bindings/script/ccui/jsb_cocos2d_ui.js @@ -373,100 +373,106 @@ ccui.Scale9Sprite.prototype.updateWithBatchNode = function (batchNode, originalR this.updateWithSprite(sprite, originalRect, rotated, cc.p(0, 0), cc.size(originalRect.width, originalRect.height), capInsets); }; -/** - * The WebView support list of events - * @type {{LOADING: string, LOADED: string, ERROR: string}} - */ -ccui.WebView.EventType = { - LOADING: "loading", - LOADED: "load", - ERROR: "error", - JS_EVALUATED: "js" -}; -ccui.WebView.prototype._loadURL = ccui.WebView.prototype.loadURL; -ccui.WebView.prototype.loadURL = function (url) { - if (url.indexOf("http://") >= 0) - { - this._loadURL(url); - } - else - { - this.loadFile(url); - } -}; +if (ccui.WebView) +{ + /** + * The WebView support list of events + * @type {{LOADING: string, LOADED: string, ERROR: string}} + */ + ccui.WebView.EventType = { + LOADING: "loading", + LOADED: "load", + ERROR: "error", + JS_EVALUATED: "js" + }; -ccui.WebView.prototype.setEventListener = function(event, callback){ - switch(event) - { - case ccui.WebView.EventType.LOADING: - this.setOnShouldStartLoading(callback); - break; - case ccui.WebView.EventType.LOADED: - this.setOnDidFinishLoading(callback); - break; - case ccui.WebView.EventType.ERROR: - this.setOnDidFailLoading(callback); - break; - case ccui.WebView.EventType.JS_EVALUATED: - //this.setOnJSCallback(callback); - cc.log("unsupport web event:" + event); - break; - default: - cc.log("unsupport web event:" + event); - break; - } -}; + ccui.WebView.prototype._loadURL = ccui.WebView.prototype.loadURL; + ccui.WebView.prototype.loadURL = function (url) { + if (url.indexOf("http://") >= 0) + { + this._loadURL(url); + } + else + { + this.loadFile(url); + } + }; -/** - * The VideoPlayer support list of events - * @type {{PLAYING: string, PAUSED: string, STOPPED: string, COMPLETED: string}} - */ -ccui.VideoPlayer.EventType = { - PLAYING: "play", - PAUSED: "pause", - STOPPED: "stop", - COMPLETED: "complete" -}; + ccui.WebView.prototype.setEventListener = function(event, callback){ + switch(event) + { + case ccui.WebView.EventType.LOADING: + this.setOnShouldStartLoading(callback); + break; + case ccui.WebView.EventType.LOADED: + this.setOnDidFinishLoading(callback); + break; + case ccui.WebView.EventType.ERROR: + this.setOnDidFailLoading(callback); + break; + case ccui.WebView.EventType.JS_EVALUATED: + //this.setOnJSCallback(callback); + cc.log("unsupport web event:" + event); + break; + default: + cc.log("unsupport web event:" + event); + break; + } + }; +} +if (ccui.VideoPlayer) +{ + /** + * The VideoPlayer support list of events + * @type {{PLAYING: string, PAUSED: string, STOPPED: string, COMPLETED: string}} + */ + ccui.VideoPlayer.EventType = { + PLAYING: "play", + PAUSED: "pause", + STOPPED: "stop", + COMPLETED: "complete" + }; -ccui.VideoPlayer.prototype._setURL = ccui.VideoPlayer.prototype.setURL; -ccui.VideoPlayer.prototype.setURL = function (url) { - if (url.indexOf("http://") >= 0) - { - this._setURL(url); - } - else - { - this.setFileName(url); - } -}; + ccui.VideoPlayer.prototype._setURL = ccui.VideoPlayer.prototype.setURL; + ccui.VideoPlayer.prototype.setURL = function (url) { + if (url.indexOf("http://") >= 0) + { + this._setURL(url); + } + else + { + this.setFileName(url); + } + }; -ccui.VideoPlayer.prototype.setEventListener = function(event, callback){ - if (!this.videoPlayerCallback) - { - this.videoPlayerCallback = function(sender, eventType){ - cc.log("videoEventCallback eventType:" + eventType); - switch (eventType) { - case 0: - this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING](sender); - break; - case 1: - this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED](sender); - break; - case 2: - this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED](sender); - break; - case 3: - this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED](sender); - break; - default: - break; - } - }; - this.addEventListener(this.videoPlayerCallback); - } - this["VideoPlayer_"+event] = callback; -}; + ccui.VideoPlayer.prototype.setEventListener = function(event, callback){ + if (!this.videoPlayerCallback) + { + this.videoPlayerCallback = function(sender, eventType){ + cc.log("videoEventCallback eventType:" + eventType); + switch (eventType) { + case 0: + this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PLAYING](sender); + break; + case 1: + this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.PAUSED](sender); + break; + case 2: + this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.STOPPED](sender); + break; + case 3: + this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED] && this["VideoPlayer_"+ccui.VideoPlayer.EventType.COMPLETED](sender); + break; + default: + break; + } + }; + this.addEventListener(this.videoPlayerCallback); + } + this["VideoPlayer_"+event] = callback; + }; +} /* * UIWidget temporary solution to addChild * addNode and addChild function should be merged in ccui.Widget diff --git a/tests/cpp-tests/Resources/cocosvideo.mp4 b/tests/cpp-tests/Resources/cocosvideo.mp4 index 194e0d2503..263ea8bbac 100644 Binary files a/tests/cpp-tests/Resources/cocosvideo.mp4 and b/tests/cpp-tests/Resources/cocosvideo.mp4 differ diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index d67bdac67c..38c7824c63 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -528,24 +528,29 @@ return new UIRichTextTest(); } } - ], - "UIVideoPlayer": [ + ] + }; + + if (cc.sys.os == cc.sys.OS_ANDROID || cc.sys.os == cc.sys.OS_IOS || !cc.sys.isNative) + { + testingItems["UIVideoPlayer"] = [ { title: "UIVideoPlayerTest", func: function () { return new UIVideoPlayerTest(); } } - ], - "UIWebViewTest": [ + ]; + + testingItems["UIWebViewTest"] = [ { title: "UIWebViewTest", func: function () { return new UIWebViewTest(); } } - ] - }; + ]; + } var guiTestScene = null; global.GUITestScene = cc.Class.extend({