我尝试使用以下代码切换youtube视频而不重页:
<code>
function setSource(url, type) {
var vid = $('#player1').first();
if (vid.attr('type') != type) {
vid.get(0).player.remove();
vid.attr('type', type).attr('src', url);
vid.mediaelementplayer({
success: function(media, dom, player) {
player.play();
}
})
}
}
</code>
和
<code>
$('#idThatSwitches').click(function (e) {
// switch out player's video source and reload
player = $('#player1')[0].player.media;
player.setSrc('https://www.youtube.com/watch?v=hLQl3WQQoQ0');
console.log(player.media);
player.load();
});
</code>
我在控制台调试器中遇到的错误是:TypeError: this.pluginApi.setSrc is not a function
媒体元素版本为3.0。