Detect if client allows inline media playback for HTML5 video

后端 未结 4 1884
感情败类
感情败类 2020-12-28 16:43

Is there a good way to detect if a client browser allows inline media playback for HTML5 video?

Update

I am not trying to s

4条回答
  •  佛祖请我去吃肉
    2020-12-28 17:11

    In iOS10 you can now have a video play inline if the playsinline attribute is added to the video tag.

    You can detect this with ('playsInline' in document.createElement('video')).

    However this isn't sufficient because this won't exist on desktop browsers - where obviously playing inline is a standard feature.

    So this is what I came up with : If not iPhone / iPad then we just assume video can be played inline (this may fail for certain android devices). Otherwise run the test above to check for iOS10

    Here is my Modernizr test.

            Modernizr.addTest('inpagevideo', function ()
            {
                return navigator.userAgent.match(/(iPhone|iPod)/g) ? ('playsInline' in document.createElement('video')) : true;
            });
    

提交回复
热议问题