YouTube - 如何只播放没有音频的视频?
YouTube - how to play video only without audio?
我有一个视频想在网站上播放 www.paypal.com
在登陆时播放一个没有音频的视频。
这是BUG吗?但是当我尝试如下时,我根本无法静音,即使音量参数设置为 0.
如何静音?
<iframe id="bg" src="https://www.youtube.com/embed/VfcZsyhUJ48?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1&enablejsapi=1&rel=0" frameborder="0" volume="0"
style="width: 100%;height:100%;
opacity: 0.80 !important;"
allowtransparency="true"></iframe>
编辑:
巨魔1:如何从低到高玩?取决于移动用户?
/*
Yes there is:
https://www.youtube.com/embed/kObNpTFPV5c?vq=hd1440
https://www.youtube.com/embed/kObNpTFPV5c?vq=hd1080
etc...
Options are:
Code for 1440: vq=hd1440
Code for 1080: vq=hd1080
Code for 720: vq=hd720
Code for 480p: vq=large
Code for 360p: vq=medium
Code for 240p: vq=small
*/
巨魔 2:如何随机播放 Youtube 视频?
/* YouTube - playlister*/
var videos = [];
videos[0] = 'youtubeID';
videos[1] = 'youtubeID';
videos[2] = 'youtubeID';
videos[3] = 'youtubeID';
var ii = Math.floor( (Math.random()*4 ) );
var play_now = videos[ii];
var yt = 'https://www.youtube.com/embed/'+ play_now + '?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1&enablejsapi=1&rel=0&vq=medium';
喷子3:YouTube视频结束后如何继续播放? loop=true 不起作用?
function onStateChange(e) {
if (e.data === YT.PlayerState.ENDED) {
player.playVideo();
}
}
或
onStateChange: function(e){
var id = 'qzZuBWMnS08';
if(e.data === YT.PlayerState.ENDED){
player.loadVideoById(id);
}
}
尝试添加新的数据属性volume="0"
Well, the volume="0" no longer seems to work but the code below does:
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '195',
width: '260',
videoId: 'h3P1OR9gg2Y',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.setVolume(0);
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 6000);
done = true;
}
event.target.setVolume(0);
}
</script>
我有一个视频想在网站上播放 www.paypal.com
在登陆时播放一个没有音频的视频。
这是BUG吗?但是当我尝试如下时,我根本无法静音,即使音量参数设置为 0.
如何静音?
<iframe id="bg" src="https://www.youtube.com/embed/VfcZsyhUJ48?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1&enablejsapi=1&rel=0" frameborder="0" volume="0"
style="width: 100%;height:100%;
opacity: 0.80 !important;"
allowtransparency="true"></iframe>
编辑:
巨魔1:如何从低到高玩?取决于移动用户?
/*
Yes there is:
https://www.youtube.com/embed/kObNpTFPV5c?vq=hd1440
https://www.youtube.com/embed/kObNpTFPV5c?vq=hd1080
etc...
Options are:
Code for 1440: vq=hd1440
Code for 1080: vq=hd1080
Code for 720: vq=hd720
Code for 480p: vq=large
Code for 360p: vq=medium
Code for 240p: vq=small
*/
巨魔 2:如何随机播放 Youtube 视频?
/* YouTube - playlister*/
var videos = [];
videos[0] = 'youtubeID';
videos[1] = 'youtubeID';
videos[2] = 'youtubeID';
videos[3] = 'youtubeID';
var ii = Math.floor( (Math.random()*4 ) );
var play_now = videos[ii];
var yt = 'https://www.youtube.com/embed/'+ play_now + '?autoplay=1&controls=0&loop=1&showinfo=0&modestbranding=1&disablekb=1&enablejsapi=1&rel=0&vq=medium';
喷子3:YouTube视频结束后如何继续播放? loop=true 不起作用?
function onStateChange(e) {
if (e.data === YT.PlayerState.ENDED) {
player.playVideo();
}
}
或
onStateChange: function(e){
var id = 'qzZuBWMnS08';
if(e.data === YT.PlayerState.ENDED){
player.loadVideoById(id);
}
}
尝试添加新的数据属性volume="0"
Well, the volume="0" no longer seems to work but the code below does:
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '195',
width: '260',
videoId: 'h3P1OR9gg2Y',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.setVolume(0);
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 6000);
done = true;
}
event.target.setVolume(0);
}
</script>