我正在使用dailymotion api播放视频。示例直接来自文档:
http://www.dailymotion.com/doc/api/player.html#api-reference
它在控制台中给我错误:
<!-- This <div> tag will be replaced the <iframe> video player -->
<div id="player"></div>
<script>
// This code loads the Dailymotion Javascript SDK asynchronously.
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//api.dmcdn.net/all.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(e, s);
}());
// This function init the player once the SDK is loaded
window.dmAsyncInit = function()
{
// PARAMS is a javascript object containing parameters to pass to the player if any (eg: {autoplay: 1})
var player = DM.player("player", {video: "x1bpnpt", width: "640", height: "360", params: {autoplay: 1}});
// 4. We can attach some events on the player (using standard DOM events)
player.addEventListener("apiready", function(e)
{
e.target.play();
});
};
</script>
但是如果我将它直接嵌入iframe然后它可以工作(它也会显示一些错误,但不会显示上面的错误):
<iframe src="http://www.dailymotion.com/embed/video/x1bpnpt?api=true&autoplay=1" width="640" height="360" frameborder="0"></iframe>
有什么问题?
答案 0 :(得分:0)
正如我正在查看的那样,js文件未正确加载,请查看
e.src = document.location.protocol + '//api.dmcdn.net/all.js';
行
document.location.protocol
前缀域前面 // api.dmcdn.net/all.js 。
所以请看一下,让我知道。