最近在做一个业务,需要多次频繁切换内容播放。
仿效Cocos2dxVideoView,Cocos2dxVideoHelper
集成了Android端的 Vitamio播放器 Ijk播放器等进行测试。
发现在修改播放地址的时候, JS层会销毁播放器并重建
这直接导致 JS=>C/C++ => Java Cocos2dxVideoHelper里面的Cocos2dxVideoView会不断创建新的
这么做是有什么专门的目的吗是不是为了防止什么事情发生?
相关代码在 CocosCreator\resources\builtin\jsb-adapter\engine\jsb-videoplayer.js
CocosCreator引擎2.1版本
…
_p.createDomElementIfNeeded = function () {
if (!jsb.VideoPlayer) {
cc.warn('VideoPlayer only supports mobile platform.');
return null;
}
if (!this._video) {
this._video = new jsb.VideoPlayer();
}
};
_p.removeDom = function () {
var video = this._video;
if (video) {
this._video.stop();
this._video.setVisible(false);
var cbs = this.__eventListeners;
cbs.loadedmetadata = null;
cbs.ended = null;
cbs.play = null;
cbs.pause = null;
cbs.click = null;
cbs.onCanPlay = null;
}
this._video = null;
this._url = "";
};
_p.setURL = function (path) {
var source, extname;
if (this._url === path) {
return;
}
this.removeDom(); //////////////////////////////////主要是这里///////////////////////////////
this._url = path;
this.createDomElementIfNeeded(); //////////////////////////////////主要是这里///////////////////////////////
this._bindEvent();
var video = this._video;
if (!video) {
return;
}
video.setVisible(this._visible);
this._loaded = false;
this._played = false;
this._playing = false;
this._loadedmeta = false;
video.setURL(this._url);
};
