燕山大学---秦皇岛

微信 HTML5 VIDEO 视频播放解决方案

2017-08-01  本文已影响383人  Vinashed

webkit-playsinline && playsinline="true"

x-webkit-airplay="allow"

x5-video-player-type="h5"

x5-video-player-fullscreen="true"

window.onresize = function(){
    test_video.style.width = window.innerWidth + "px";
    test_video.style.height = window.innerHeight + "px";
}

x5-video-orientation控制横竖屏

<video x5-video-player-type="h5" x5-video-orientation="landscape|portrait"/>

方法

自动播放

setTimeout(function () { video.play(); }, 1000);
video.addEventListener('touchstart', function () {
    video.play();
});

进入全屏状态

video.on('x5videoenterfullscreen', function() {
    //延时修改video尺寸以占满全屏
    //$(this).attr('x5-video-player-type','');
    setTimeout(function() {
        $('video').css({
            width: window.innerWidth,
            height: window.innerHeight,
        });
    }, 200);
});

退出全屏状态

//退出全屏状态
video.on('x5videoexitfullscreen', function() {
    //清除
    $(this).css({
        width: '',
        height: '',
    });
});

控制video同层播放位置

video {
    object-position: 0 0;
}

获取视频缓存进度

function gp() {
    var _this=video;// video为当前video元素
    var percent=null;
    // FF4+, Chrome
    if (_this && _this.buffered && _this.buffered.length > 0 && _this.buffered.end && _this.duration) {
        percent = _this.buffered.end(0) / _this.duration;
    }
    // Some browsers (e.g., FF3.6 and Safari 5) cannot calculate target.bufferered.end()
    // to be anything other than 0. If the byte count is available we use this instead.
    // Browsers that support the else if do not seem to have the bufferedBytes value and
    // should skip to there. Tested in Safari 5, Webkit head, FF3.6, Chrome 6, IE 7/8.
    else if (_this && _this.bytesTotal != undefined && _this.bytesTotal > 0 && _this.bufferedBytes != undefined) {
        percent = _this.bufferedBytes / _this.bytesTotal;
    }
    if (percent !== null) {
        percent = 100 * Math.min(1, Math.max(0, percent));
        return percent;
    }
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读