我有一个使用 Player api (http://www.dailymotion.com/doc/api/player.html) 的 Dailymotion 嵌入式播放器。它适用于台式机和 Android 平板电脑。但在 iOS 设备上,视频无法启动。我的代码如下:
<!-- 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: 'somevideoid', width: "100%", height: "100%", params: {autoplay: 0}});
// 4. We can attach some events on the player (using standard DOM events)
player.addEventListener("apiready", function(e)
{
e.target.play();
});
};
</script>
最佳答案
您的代码完全有效。问题是大多数移动设备,包括 iOS 设备,都会阻止自动播放视频(请参阅 Apple documentation : Safari HTML5 Audio and Video Guide)。在这些设备上,第一次播放必须由用户交互触发,例如触摸播放按钮,否则它会被浏览器忽略。
apiready
事件由 Dailymotion SDK 触发,不是用户事件。这就是为什么 play()
方法对视频没有影响。
[编辑]:你宁愿调用。
此外,由于 Dailymotion Player 嵌入在 play()
来自另一个事件监听器的方法,例如 click
或 touchend
事件。<iframe>
中。 ,父页面与<iframe>
之间的通信将始终被浏览器视为编程事件,无论来自父页面的原始事件是否来自用户。
TLDR:在移动设备上,您必须等待用户触摸播放器的开始屏幕。
关于ios - iOS 设备上的 Dailymotion 嵌入式播放器 (HTML5),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24372401/