微信、video、前端,全屏问题、IOS和安卓适配问题

<div id="mov">

<video id="video"
                airplay
                x-webkit-airplay="true" //微信x5内核设置
                x5-playsinline="true" //微信x5内核设置
                x5-video-player-type="true"//针对x5内核设置
                x5-video-player-fullscreen="true"//针对x5内核设置
                playsinline="false"
                webkit-playsinline="true"//针对ios环境下
                poster="img/movStart.jpg" //开始屏幕展示
                preload='auto'>
                </video>

</div>

问题:在安卓下无法全屏?

处理:需要给视频标签添加属性css设置以及js设置

$('video').css({
        width: window.innerWidth,
        height: window.innerHeight,
        width: '100%',
        height: '100%',
      });

$video[0].addEventListener('x5videoenterfullscreen', function() {
        $video.addClass('android-full');
    });
    $video[0].addEventListener('x5videoexitfullscreen', function() {
        $video.removeClass('android-full');
    });

CSS设置:

#mov{
    position: absolute;
    display: none;
    width: 20rem;
    height: 35.5555556rem;
    top:50%;
    left:50%;
    transform: translate3d(-50%, -50%, 0);
    background-size: 100% auto;
}

video {
    width: 100%;
    height: 100%;
}

video.android-full {
    position: relative;
    height: 100%;
    object-fit: cover;
    object-position: left 0 top 0;
}

video.android-full::-webkit-media-controls-enclosure {
    -webkit-appearance: none;
    position: absolute;
}

video.android-full::-webkit-media-controls-current-time-display{
    display: none;
}

video.android-full::-webkit-media-controls-fullscreen-button {
    display: none;
}
video.android-full::-webkit-media-controls-play-button {}
video.android-full::-webkit-media-controls-timeline {}
video.android-full::-webkit-media-controls-current-time-display{}
video.android-full::-webkit-media-controls-time-remaining-display {}
video.android-full::-webkit-media-controls-mute-button {}
video.android-full::-webkit-media-controls-toggle-closed-captions-button {}
video.android-full::-webkit-media-controls-volume-slider {}

问题1、在IOS系统下播放video的同时播放audio,只能有一个声音?

处理:在视频播放的同时将音乐和和视频一起播放,只需要将音频静音和音量设为0

bgAudio = $("#bgAudio")[0];
    bgAudio.src = path;
    bgAudio.load();
    bgAudio.currentTime = 0;
    bgAudio.volume = 0;
    bgAudio.muted = true;
    bgAudio.play();

问题2、在视频播放完毕出现画面可能会出现闪黑画面?

处理:在视频播放到接近尾部的时候,先将后续画面display设为block

//处理视频在播放到几秒的时候处理事件

document.getElementById("video").addEventListener('timeupdate', function (e) {
        var timeDisplay;
        timeDisplay = Math.floor(video.currentTime)
        if(timeDisplay == 9){

           //在视频播放到第九秒的时候处理事件
        }
    })

//处理视频播放结尾的时候处理事件

document.getElementById("video").addEventListener('ended', function (e) {
     //需要处理的事件
    })

猜你喜欢

转载自blog.csdn.net/qq_22266149/article/details/89144432
今日推荐