问题描述
我在我的网站上嵌入了一个Facebook的视频,并将其设置在自动播放中,但声音静音,除非您单击音量并播放声音。您实际上可以使用来控制您的网站中的嵌入式视频,例如在页面加载时取消静音。
请注意,这并不适用于嵌入视频通过< iframe>
标签。使用链接中提到的< div>
标签(或参见下面的示例)。
这是一个示例脚本我从链接中插入 my_video_player.unmute()
在 xfbml.ready
事件中。确保您提供正确的 FB appId
。
< html>
< head>
< title>您的网站标题< / title>
< / head>
< body>
<! - 加载Facebook SDK for JavaScript - >
< div id =fb-root>< / div>
< script>
window.fbAsyncInit = function(){
FB.init({
appId:'{your-app-id}',
xfbml:true,
version :'v2.5'
});
//获取嵌入式视频播放器API实例
var my_video_player;
FB.Event.subscribe('xfbml.ready',function(msg){
if(msg.type ==='video'){
my_video_player = msg.instance;
my_video_player.unmute();
}
});
};
(function(d,s,id){
var js,fjs = d.getElementsByTagName(s)[0];
if(d.getElementById(id) {return;}
js = d.createElement(s); js.id = id;
js.src =//connect.facebook.net/en_US/sdk.js;
fjs.parentNode.insertBefore(js,fjs);
}(document,'script','facebook-jssdk'));
< / script>
<! - 您的嵌入式视频播放器代码 - >
< div
class =fb-video
data-href =https://www.facebook.com/facebook/videos/10153231379946729/
data- width =500
data-autoplay =true
data-allowfullscreen =true>< / div>
< / body>
< / html>
I embedded a video from facebook in my website and i set it in autoplay, but the sound is muted unless you click the volume and it will play the sound.
You can actually use Facebook Embedded Video Player API to control your embedded video in your website, such as unmuting it on page load.
Take note that this doesn't work on embedding videos thru <iframe>
tag. Use the <div>
tag as mentioned in the link (or see sample below).
Here's a sample script I got from the link, with insertion of my_video_player.unmute()
on xfbml.ready
event. Make sure you provide the proper FB appId
.
<html>
<head>
<title>Your Website Title</title>
</head>
<body>
<!-- Load Facebook SDK for JavaScript -->
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '{your-app-id}',
xfbml : true,
version : 'v2.5'
});
// Get Embedded Video Player API Instance
var my_video_player;
FB.Event.subscribe('xfbml.ready', function(msg) {
if (msg.type === 'video') {
my_video_player = msg.instance;
my_video_player.unmute();
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<!-- Your embedded video player code -->
<div
class="fb-video"
data-href="https://www.facebook.com/facebook/videos/10153231379946729/"
data-width="500"
data-autoplay="true"
data-allowfullscreen="true"></div>
</body>
</html>
这篇关于在Facebook嵌入式视频中设置自动播放时如何启用声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!