【发布时间】:2011-05-18 21:57:46
【问题描述】:
我正在使用 JQuery 和 YouTube JS API 制作视频播放器,我有多种方法来控制 youtube 播放器对象,例如:
setVolumen: function (value) {
if (value < 0 || value > 100) {
this.throwError("Volumen inválido: "+ value);
return;
}
this.volume = value;
this.elements.player.each(function () {
if (typeof this.setVolume != "undefined") {
this.setVolume(value);
}
});
},
"this.elements.player" 是 yt 播放器对象的 jquery 选择器。我从 player-controll 实例调用 setVolume 方法并工作。例如:
// This is inside a method of controller class
// and self is a reference to "this" in method context
this.celements.volume.slider({
max: 100,
value: 100,
change: function (event, obj) {
self.setVolumen(obj.value);
}
});
如果我移动滑块元素,这没有问题,购买我从 jquery 选择器调用一个方法:
$('#playlist').UplayList('setVolumen',80);
这抛出了“错误:在 NPObject 上调用方法时出错!”
对象存在,并且 setVolume 不是未定义的。我不明白。
在 Jquery 中有一个:
$.fn.extend({
UplayList: function (options) {
this.each(function () {
if ($(this).data('uplaylistId')) {
var instance = $.playList.instances[$(this).data('uplaylistId')];
instance[options].apply( instance, Array.prototype.slice.call( arguments, 1 ));
} else {
var instance = new $.playList(this, options);
var id = instance.elements.player.attr('id');
$(this).data('uplaylistId',id);
}
});
}
});
【问题讨论】:
标签: javascript jquery youtube