为了子孙后代,这就是我按照罗曼的建议最终做的事情。下面的插件几乎是最低限度的,但这正是我想要它做的。
在嵌入中,我们需要声明自定义插件:
kWidget.embed({
...
"flashvars": {
...
"sourceExposure": {
"plugin": true,
"iframeHTML5Js": "js/sourceExposure.js"
}
}
}
在js/sourceExposure.js
中,我们需要声明一个插件来提供对自定义事件的响应(这里是“customDoSwitch”):
(function(mw,$) {
mw.kalturaPluginWrapper(function() {
mw.PluginManager.add( 'sourceExposure', mw.KBaseComponent.extend({
setup: function() {
var _this = this;
this.bind('customDoSwitch', function(evt, flavorIndex) {
var sources = _this.getSources().slice(0)
if (flavorIndex >= sources.length) {
_this.log("Flavor Index too large.");
return;
}
_this.getPlayer.switchSrc(_this.getSources()[flavorIndex]);
})
},
getSources: function() {
return this.getPlayer().getSources()
}
}));
});
})(window.mw, window.jQuery)
当我们想要切换到不同的风味时,我们现在可以使用自定义事件并传递风味索引:
kdp.sendNotification("customDoSwitch", 2) //switches to flavor index 2