如何使嵌入式 Youtube 播放器静音? [英] How do you mute an embedded Youtube player?

查看:25
本文介绍了如何使嵌入式 Youtube 播放器静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Youtube 播放器,但我无法让它默认静音.

I'm experimenting with the Youtube player but I can't get it to mute by default.

function onPlayerReady() {
    player.playVideo();
    // Mute?!
    player.mute();
    player.setVolume(0);
}

如何从一开始就静音?

小提琴

更新:

JavaScript Player API 已弃用.
请改用 iframe 嵌入.

推荐答案

结果 player.mute() 工作正常.它只需要参数enablejsapi=1.小提琴中的初始测试不起作用,因为播放器启动有错误.以下工作.

Turns out player.mute() works fine. It only needed the parameter enablejsapi=1. Initial test in the fiddle didn't work because the player initiation had an error. The following works.

HTML:

<iframe id="ytplayer" type="text/html" src="https://www.youtube-nocookie.com/embed/zJ7hUvU-d2Q?rel=0&enablejsapi=1&autoplay=1&controls=0&showinfo=0&loop=1&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>

JS:

var player;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('ytplayer', {
        events: {
            'onReady': onPlayerReady
        }
    });
}

function onPlayerReady(event) {
    player.mute();
    player.playVideo();
}

小提琴

感谢 Gagandeep Singh 和 Anton King 指向 enablejsapi=1

这篇关于如何使嵌入式 Youtube 播放器静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆