微信内置浏览器 非全屏播放视频解析

 1 E币 
成为会员,免费下载资料
文件大小:85.5 KB 上传者:A-小鲸鱼 时间:2020-02-13 14:45:07 下载量:8

前提条件,接了一个项目要实现在微信公众号里课程播放,而且还有评论功能,视频需要小窗播放。
首先公布解决方案:

感谢知乎上的回答,原版微信内置浏览器 如何小窗不全屏播放视频?
感谢该问题的徐霖同学的回答,虽然我们不认识,但是很感谢对我的帮助,写这个还是主要是为了徐霖同学对我的这次帮助

 <video id="my-video" class="video-js" controls preload="auto" width="100%" height="300px"
  x5-playsinline="" playsinline="" webkit-playsinline="" poster="" preload="auto"></video>

解决过程:

webkit-playsinline="true"   
  playsinline="true"   
  x-webkit-airplay="allow"
  x5-video-player-type="h5"  
  x5-video-player-fullscreen="true" >
  x5-video-orientation="portraint" 

还有用canvas解决的,代码可以给你们参考写是我从csdn花了3C币买的

请自动引入jq等插件库

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="author" content="Tencent-TGideas">
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui"/>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <title>直播</title>
    <style>
        *{ margin:0; padding:0; box-sizing:border-box;}
        html{ max-width:640px; min-width:320px; margin:0 auto;}
        img{ max-width:100%; vertical-align:middle;}
        .video_box{ width:100%; position:relative;}
        .start_video{ width:40px; height:40px; border-radius:50%; background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAH4AAAB+CAYAAADiI6WIAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyFpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0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XF8AkJF+7srDwI7EeTx6aef0qZNmyy3kweTtHvvvZcee+wxI1hCiYVzqS5LIcsOJvyMj/QXnMRLFYALaiTVbdR0Wy5k41q3bh1t2LCBsrOzA5amBR4z5JHDLmKkFVMSDZkRXiQIP+1jvQU38UoPgO4fER2Nns+K41APHTpEubm5tGvXLtq3b5/fki9j+xgmZ1h3I9cvXKZNOKoNJ3zBALPHVy3ctsRLFQoX5A9CA2vq76FHKCgooKKiIjpy5AiVlpbSiRMnjOPRIRUVFUZSJ1yBiIgII18MrjiICdKtWzfq0aOHsT0JQSUwqV6hRatAqz4I0kWiCX/qyV7EK5W7UcwBMAx0sGgxYWXDhoZCJvu/zagb+xIvVRLlhfm3DwsOWukawDpA48gNi5x5JSwnRK7A5taJ/Yl3Mxx0Z4EpDL0CwlXC/fR16LKxpkRrRqzbcX9345p4zxTRQcwJrmXpKIaGduKFCBcTxhbSxBETsBpxrRJyQXTdZ6nusKbTTXGYBBPx/xdgAMLpyy1uaqOxAAAAAElFTkSuQmCC) no-repeat center center; background-size:100% 100%; cursor:pointer; position:absolute; left:50%; top:50%; -webkit-transform:translate(-50%,-50%); transform:translate(-50%,-50%);}
        video{ width:100%; vertical-align:middle; object-fit:contain; object-position:left top;}
    </style>
</head>
<body>



<div><img src="http://pic.qiantucdn.com/58pic/11/32/07/98258PIC8dA.jpg" /></div>



<div class="video_box">
    <!--
        必须加上:
                x5-video-player-type='h5' x5-video-player-fullscreen='true'  否则视频还是跳出去 全屏 播放
                poster="http://ossweb-img.qq.com/images/wefire/act/a20150826kris/bg_poster.jpg"  否则视频的高度可能会出问题
    -->
    <video id="testVideo" x-webkit-airplay="true" webkit-playsinline="true" playsinline="true" preload="auto" x5-video-player-type='h5' x5-video-player-fullscreen='true' src="http://ossweb-img.qq.com/images/wefire/act/a20150826kris/v1.mp4" poster="http://ossweb-img.qq.com/images/wefire/act/a20150826kris/bg_poster.jpg"></video>

    <span class="start_video"></span>
</div>



<div style=" height:300px;">
    <textarea style=" width:100%; height:100%; padding:10px; background-color:#eee; border:none; outline:none vertical-align:middle; resize:none; appearance:normal;" placeholder="在此输入内容"></textarea>
</div>
<div><img src="http://pic.qiantucdn.com/58pic/11/32/07/98258PIC8dA.jpg" /></div>

<script src="http://code.jquery.com/jquery-2.0.0.min.js"></script>
<script>
    //判断是否为安卓设备
    function isAndroid(){
        var u = navigator.userAgent;
        if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
            return true;
        }
    }
    var $video = $('#testVideo');
    $(function(){
        $('.start_video').on("touchstart",function(){
            $(this).hide();
            $video[0].play();
        });
        if(isAndroid()){
            $video.css('display','none').after('<canvas id="testCanvas" style="width:100%; vertical-align:middle;"></canvas>');
            
            var videoW , videoH;
            setTimeout(function(){
                videoW = $video.width() * 3;
                videoH = $video.height() * 3;
                TestCanvas.width = videoW;
                TestCanvas.height = videoH;

                setCanvasStartImg();
                //之所以这里要播放下,是因为经过测试,第一次点击CANVAS时,视频播放又立即停止了
                TestVideo.play();
                TestVideo.pause();

                console.log(videoW);
                console.log(videoH);
                console.log(TestVideo.width);
                console.log(TestVideo.height);
            },100);
            //设置CANVAS初始画面(视频封面)
            function setCanvasStartImg(){
                var plsterImgSrc = $video.attr('poster');
                if(plsterImgSrc){
                    var plsterImg = new Image();
                    plsterImg.src = plsterImgSrc;
                    plsterImg.onload = function(){
                        TestCanvas2D.drawImage(plsterImg,0,0,videoW,videoH);
                    }
                }
            }

            

            //获取video
            var TestVideo=document.getElementById("testVideo");
            //获取canvas画布
            var TestCanvas=document.getElementById("testCanvas");
            //设置画布
            var TestCanvas2D=TestCanvas.getContext('2d');
            //设置setinterval定时器
            var TestVideoTimer=null;
            //监听播放
            TestVideo.addEventListener('play',function() {
                $('.start_video').hide();
                TestVideoTimer=setInterval(function() {
                    TestCanvas2D.drawImage(TestVideo,0,0,videoW,videoH);
                },20);

            },false);
            //监听暂停
            TestVideo.addEventListener('pause',function() {
                clearInterval(TestVideoTimer);
                $('.start_video').show();
            },false);
            //监听结束
            TestVideo.addEventListener('ended',function() {
                clearInterval(TestVideoTimer);
                $('.start_video').show();
            },false);
        }else{
            $video.attr('controls','controls');
        }

    });
</script>
</body>
</html>


展开
折叠
893
评论
共 0 个
内容存在敏感词
    易百纳技术社区暂无数据
相关资料
关于作者
易百纳技术社区
A-小鲸鱼
贡献资料 1241
易百纳技术社区 我上传的资料
登录查看
我赚取的积分
登录查看
我赚取的收益
登录查看
上传资料 赚取积分兑换E币
易百纳技术社区
删除原因
广告/SPAM
恶意灌水
违规内容
文不对题
重复发帖
置顶时间设置
结束时间
举报反馈

举报类型

  • 内容涉黄/赌/毒
  • 内容侵权/抄袭
  • 政治相关
  • 涉嫌广告
  • 侮辱谩骂
  • 其他

详细说明

审核成功

发布时间设置
发布时间:
是否关联周任务-资料模块

审核失败

失败原因
备注
易百纳技术社区