/**************************************************************************** Copyright (c) 2013-2016 Chukong Technologies Inc. http://www.cocos.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated engine source code (the "Software"), a limited, worldwide, royalty-free, non-assignable, revocable and non-exclusive license to use Cocos Creator solely to develop games on your target platforms. You shall not use Cocos Creator software for developing other software or tools that's used for developing games. You are not granted to publish, distribute, sublicense, and/or sell copies of Cocos Creator. The software or tools in this License Agreement are licensed, not sold. Chukong Aipu reserves all rights not expressly granted to you. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ****************************************************************************/ /** * @class * @extends _ccsg.Node * @brief Displays a video file. * * @note VideoPlayer displays a video file based on DOM element * VideoPlayer will be rendered above all other graphical elements. * * @property {String} path - The video path */ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ ctor: function () { _ccsg.Node.prototype.ctor.call(this); // 播放结束等事件处理的队列 this._EventList = {}; }, _createRenderCmd: function(){ return new _ccsg.VideoPlayer.RenderCmd(this); }, setURL: function (url) { this._renderCmd.updateURL(url); }, getURL: function() { return this._renderCmd._url; }, play: function () { this._renderCmd.play(); }, pause: function () { this._renderCmd.pause(); }, _resume: function () { this._renderCmd.play(); }, stop: function () { this._renderCmd.stop(); }, seekTo: function (time) { this._renderCmd.seekTo(time); }, isPlaying: function () { return this._renderCmd.isPlaying(); }, createDomElementIfNeeded: function () { if (!this._renderCmd._video) { this._renderCmd.createDom(); } }, setKeepAspectRatioEnabled: function () { cc.log("On the web is always keep the aspect ratio"); }, isKeepAspectRatioEnabled: function () { return true; }, setFullScreenEnabled: function (enable) { var video = this._renderCmd._video; if (!video) return; if(enable) cc.screen.requestFullScreen(video); else cc.screen.exitFullScreen(video); }, isFullScreenEnabled: function () { cc.log("Can't know status"); }, setEventListener: function (event, callback) { this._EventList[event] = callback; }, removeEventListener: function (event) { this._EventList[event] = null; }, _dispatchEvent: function (event) { var callback = this._EventList[event]; if (callback) callback.call(this, this, this._renderCmd._video.src); }, onPlayEvent: function () { var callback = this._EventList[_ccsg.VideoPlayer.EventType.PLAYING]; callback.call(this, this, this._renderCmd._video.src); }, setContentSize: function (width, height) { if (width.width !== undefined && width.height !== undefined) { height = width.height; width = width.width; } _ccsg.Node.prototype.setContentSize.call(this, width, height); this._renderCmd.updateSize(width, height); }, cleanup: function () { this._renderCmd.removeDom(); this.stopAllActions(); this.unscheduleAllCallbacks(); }, onEnter: function () { _ccsg.Node.prototype.onEnter.call(this); var list = _ccsg.VideoPlayer.elements; if(list.indexOf(this) === -1) list.push(this); }, onExit: function () { _ccsg.Node.prototype.onExit.call(this); var list = _ccsg.VideoPlayer.elements; var index = list.indexOf(this); if(index !== -1) list.splice(index, 1); }, setVisible: function ( visible ) { _ccsg.Node.prototype.setVisible.call(this, visible); this._renderCmd.updateVisibility(); } }); // video 队列,所有 vidoe 在 onEnter 的时候都会插入这个队列 _ccsg.VideoPlayer.elements = []; // video 在 game_hide 事件中被自动暂停的队列,用于回复的时候重新开始播放 _ccsg.VideoPlayer.pauseElements = []; cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function () { var list = _ccsg.VideoPlayer.elements; for(var node, i=0; i