From 1484a038b979c2819efab7756995262883c5993e Mon Sep 17 00:00:00 2001 From: zilongshanren Date: Mon, 17 Oct 2016 12:04:35 +0800 Subject: [PATCH] add ready to play event to videoplayer --- cocos2d/core/components/CCVideoPlayer.js | 5 +++++ cocos2d/core/label/CCSGLabel.js | 5 ++++- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 4 +++- jsb/jsb-enums.js | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/components/CCVideoPlayer.js b/cocos2d/core/components/CCVideoPlayer.js index ec6ba4db5a..52e83c431e 100644 --- a/cocos2d/core/components/CCVideoPlayer.js +++ b/cocos2d/core/components/CCVideoPlayer.js @@ -259,9 +259,14 @@ var VideoPlayer = cc.Class({ sgNode.setEventListener(EventType.COMPLETED, this.onCompleted.bind(this)); sgNode.setEventListener(EventType.META_LOADED, this.onMetaLoaded.bind(this)); sgNode.setEventListener(EventType.CLICKED, this.onClicked.bind(this)); + sgNode.setEventListener(EventType.READY_TO_PLAY, this.onReadyToPlay.bind(this)); } }, + onReadyToPlay: function () { + cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.READY_TO_PLAY); + }, + onMetaLoaded: function () { cc.Component.EventHandler.emitEvents(this.videoPlayerEvent, this, EventType.META_LOADED); }, diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 247067a0a7..33f090d269 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -142,7 +142,10 @@ _ccsg.Label = _ccsg.Node.extend({ fontHandle = fontHandle || ""; this._fontHandle = fontHandle; - string = string || ""; + if (typeof string !== 'string') { + string = '' + string; + } + this._string = string; _ccsg.Node.prototype.ctor.call(this); diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index ff197d650c..c46d4ac69b 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -196,7 +196,8 @@ _ccsg.VideoPlayer.EventType = { STOPPED: 2, COMPLETED: 3, META_LOADED: 4, - CLICKED: 5 + CLICKED: 5, + READY_TO_PLAY: 6 }; (function (video) { @@ -327,6 +328,7 @@ _ccsg.VideoPlayer.EventType = { this._loaded = true; node.setContentSize(node._contentSize.width, node._contentSize.height); video.currentTime = 0; + node._dispatchEvent(_ccsg.VideoPlayer.EventType.READY_TO_PLAY); this.updateVisibility(); this.updateMatrix(); }.bind(this); diff --git a/jsb/jsb-enums.js b/jsb/jsb-enums.js index 0f38f791fd..dd3a062637 100644 --- a/jsb/jsb-enums.js +++ b/jsb/jsb-enums.js @@ -49,7 +49,8 @@ cc.VideoPlayer.EventType = { STOPPED: 2, COMPLETED: 3, META_LOADED: 4, - CLICKED: 5 + CLICKED: 5, + READY_TO_PLAY: 6 }; cc.WebView.EventType = {