HTML5 video on iPad

后端 未结 8 1168
深忆病人
深忆病人 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:43

    automatically starts player on the ipad/iphone:

    function fakeClick(fn) {
        var $a = $('');
    
        $a.bind("click", function(e) {
            e.preventDefault();
            fn();
        });
    
        $("body").append($a);
    
        var evt,
            el = $("#fakeClick").get(0);
    
            if (document.createEvent) {
                evt = document.createEvent("MouseEvents");
                if (evt.initMouseEvent) {
                    evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                    el.dispatchEvent(evt);
                }
            }
    
            $(el).remove();
    } 
    
    $(function() {
        var video = $("#mobileVideo").get(0);
    
        fakeClick(function() {
            video.play();
        });
    });
    

提交回复
热议问题