我正在尝试加载带有 javascript 的视频,但它会导致错误...
编码:
<script src="mediaelement/build/mediaelement-and-player.min.js"></script>
<link rel="stylesheet" href="mediaelement/build/mediaelementplayer.min.css" />
<video controls="controls" preload="none" id="dinamic-video">
</video>
<script>
var player = new MediaElementPlayer('dinamic-video');
$('#btn-play').click(function(){
player.setSrc('mediaelement/media/teste-html5-MP4.mp4');
});
</script>
错误:
未捕获的类型错误:对象 # 没有方法 'setSrc'
我怎样才能正确运行它?!
--- 编辑以放置有关Ricardus答案的更多详细信息 ---
不工作...
也不执行回调成功,不加载视频
var player;
$(document).ready(function(){
var player = new MediaElementPlayer('video', {
features: ['playpause', 'progress', 'duration', 'volume'],
success: function (mediaElement) {
console.log(mediaElement);
var sources =[{ src: "mediaelement/media/teste-html5-MP4.mp4" }];
mediaElement.pause();
mediaElement.setSrc(sources);
mediaElement.load();
}
});
});