Youtube API setvolume not working on iOS?

我们两清 提交于 2019-12-07 17:28:12

问题


I have built a chromeless youtube player in a webpage, using the iframe API from the youtube dev site. Everything works like a charm, except when I view my page on an iPad or Android device, the video's volume and mute controls do not work.

_player.mute()
_player.setVolume(0);

Strangely, the other controls DO work, for example:

_player.pauseVideo();
_player.playVideo();

回答1:


It works, you just need to run it after player is ready and functioning.

But on mobile devices, volume depends on the device's own setting rather than the player. So setVolume doesn't have any effect.

Here's an example: http://jsfiddle.net/iulukaya/XQ4bz/

var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var player; function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '250',
        width: '444',
    videoId: 'M7lc1UVf-VE',
    events: {
      'onReady': onPlayerReady
    }   }); }

function onPlayerReady(event) {
    event.target.playVideo();
    event.target.setVolume(0); }


来源:https://stackoverflow.com/questions/21386594/youtube-api-setvolume-not-working-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!