HTML5 Video Tag Volume Support

痞子三分冷 提交于 2019-12-13 19:23:38

问题


i had a question on some devices like iPad and Android Tables you cannt change Volume of Video Tags becuase Volume API dont supported on this devices. have yo a idea how i can detect if this isnt support?


回答1:


The best I could come up with is this:

function volumeChangeSupported () {
    var ua = navigator.userAgent.toLowerCase();
    // got information from jplayer:
    var noVolume = /ipad|iphone|ipod|android|blackberry|windows ce|windows phone|webos|playbook/.exec(ua);

    if (noVolume) {
        if (noVolume[0] === 'android' && /gecko/.test(ua)) {
            // Firefox on android DOES support changing the volume:
            return true;
        }
        else {
            return false;
        }
    }
    return true;
}

This doesn't really "detect" support for changing the volume. I got this information partly from jPlayer and partly from my own experience testing Firefox 19 on an old Android 3 tablet. Who knows if Firefox on an Android phone or a different Android version behaves differently.

But before this I tried to detect volume change support like this:

function volumeChangeSupported () {
    var audio = new Audio();
    audio.volume = 0.5;
    return audio.volume === 0.5;
}

This yielded the correct result for iPhone Safari and Android Firefox, but not for other Android Browsers (the "Android Browser" and "Dolphin", which can't change the volume but had audio.volume === 0.5 to be true).



来源:https://stackoverflow.com/questions/12301435/html5-video-tag-volume-support

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