HTML5 video on iPad

后端 未结 8 1177
深忆病人
深忆病人 2020-12-30 03:07

I have a dynamic video gallery and it works great on a computer. When moving to an iPad, the video starts loading and it shows the cannot play icon. Instead of this I\'d r

8条回答
  •  执念已碎
    2020-12-30 03:58

    Check to see if the browser can play the video before you attempt to load it:

    function canPlayVorbis() {
        var v = document.createElement('video');
        return !!(v.canPlayType && v.canPlayType('video/ogg; codecs="theora, vorbis"').replace(/no/, ''));
    }
    
    function canPlayMP4() {
        var v = document.createElement('video');
        return !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
    }
    
    function canPlayWebM() {
        var v = document.createElement('video');
        return !!(v.canPlayType && v.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/no/, ''));
    }
    

    Taken from Dive Into HTML5 Appendix A.

提交回复
热议问题