[英]Dailymotion embedded player on iOS devices (HTML5)
I have a Dailymotion embedded player using the Player api ( http://www.dailymotion.com/doc/api/player.html ) . 我有一个使用Player api( http://www.dailymotion.com/doc/api/player.html )的Dailymotion嵌入式播放器。 It works well on a Desktop and a Android Tablet. 它在台式机和Android平板电脑上均可正常运行。 But on a iOS device, the video just doesn't start. 但是在iOS设备上,视频只是无法播放。 My code is as follows: 我的代码如下:
<!-- 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>
Your code is perfectly valid. 您的代码是完全有效的。 The thing is that most mobile devices, including iOS devices, prevent videos from being played automatically (see Apple documentation : Safari HTML5 Audio and Video Guide ). 事实是,大多数移动设备(包括iOS设备)都会阻止视频自动播放(请参阅Apple文档:Safari HTML5音频和视频指南 )。 On those devices, the first play must be triggered by a user interaction, such as touching the play button, otherwise it's ignored by the browser. 在这些设备上,第一次播放必须由用户互动触发,例如触摸播放按钮,否则浏览器将忽略它。
The apiready
event is triggered by the Dailymotion SDK and is not a user event. apiready
事件由Dailymotion SDK触发,不是用户事件。 That's why the play()
method as no effect on the video. 这就是为什么play()
方法对视频无效的原因。
[Edit]: [编辑]: You'd rather call the . 。 Also, as the Dailymotion Player is embedded within an play()
method from another event listener, such as a click
or touchend
event. 您宁愿从另一个事件侦听器(例如click
或touchend
事件play()
调用play()
方法。 <iframe>
, the communication between the parent page and the <iframe>
will always be considered as a programmatic event by the browser, no matter if the original event from the parent page comes from a user or not. 另外,由于Dailymotion Player嵌入在<iframe>
,因此浏览器始终将父页面与<iframe>
之间的通信视为编程事件,无论父页面的原始事件是否来自用户。
TLDR: On mobile device, you must wait for the user to touch the player's start screen. TLDR:在移动设备上,您必须等待用户触摸播放器的开始屏幕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.