前两天,美团推出的杨洋H5火爆朋友圈。里面主要的是多段视频播放、暂停。
听起来很简单,可是因为腾讯白名单限制,在微信浏览器,qq浏览器,会自动将video标签中非腾讯域名的视频 ,自动全屏,结尾追加视频推荐。而且白名单申请入口已经关闭。css
目前替换几种解决方案的实测。html
//html <video id="video1" :src="src_mp4" preload="auto" webkit-playsinline playsinline="true" x-webkit-airplay="allow" x5-video-player-type="h5" x5-video-player-fullscreen="true" x5-video-orientation="portraint" style="object-fit:fill"> </video> //js var video = document.querySelector('video'); videoMethod(video); function videoMethod(video) { video.addEventListener('touchstart', function () { video.play(); }); setTimeout(function () { video.play(); }, 1000); document.addEventListener("WeixinJSBridgeReady", function (){ video.play(); video.pause(); }, false); video.addEventListener('ended', function (e) { video.play(); }) //进入全屏 video.addEventListener("x5videoenterfullscreen", function(){ window.onresize = function(){ video.style.width = window.innerWidth + "px"; video.style.height = window.innerHeight + "px"; } }) //退出全屏 video.addEventListener("x5videoexitfullscreen", function(){ window.onresize = function(){ video.style.width = 原尺寸; video.style.height = 原尺寸; } }) } //引用js iphone-inline-video //css .IIV::-webkit-media-controls-play-button, .IIV::-webkit-media-controls-start-playback-button { opacity: 0; pointer-events: none; width: 5px; } .videobox { width: 4.78rem; height: 7.8rem; position: absolute; top: 3.2rem; left: 1.2rem; } video{ width: 4.2rem; height: 7.69rem; position: absolute; left: .22rem; top: .7rem; overflow: hidden; margin-top:-.7rem; }
字面意思 允许airplay (经过AirPlay能够把当前的视频投放到支持此技术的其余设备上。)vue
setTimeout(function () { video.play(); }, 1000); //微信webview全局内嵌,WeixinJSBridgeReady方法 document.addEventListener("WeixinJSBridgeReady", function (){ video.play(); video.pause(); }, false); //诱导用户触摸 video.addEventListener('touchstart', function () { video.play(); });
除ended,timeupdate其余事件慎用html5
video.addEventListener('timeupdate',function (){ //当视频的currentTime大于0.1时表示黑屏时间已过,已有视频画面,能够移除浮层(.pagestart的div元素) if ( !video.isPlayed && this.currentTime>0.1 ){ $('.pagestart').fadeOut(500); video.isPlayed = !0; } })
因咱们实现h5播放效果,须要在video上设置属性。但咱们知道react自定义属性,须要添加data-前缀。使得生成的节点属性 并非 x5要求的属性。形成失效。node
componentDidMount: function() { var element = ReactDOM.findDOMNode(this.refs.test); element.setAttribute('custom-attribute', 'some value'); }
See https://jsfiddle.net/peterjma...react
自定义属性将会被原生支持在React 16,这个在RC版本中的特性,以及即将被公布。这意味着,加入自定义属性在元素中将会很是简单:css3
render() { return ( <div custom-attribute="some-value" /> ); }
ref={(node) => { if(node){node.setAttribute('xmlns:xlink', 'w3.org/1999/xlink')} }}
直接放在template中就能够了git
<template> <div class="videobox"> <video id="video1" :src="src_mp4" preload="auto" webkit-playsinline playsinline x-webkit-airplay="allow" x5-video-player-type="h5" x5-video-player-fullscreen="true" x5-video-orientation="portraint" style="object-fit:fill"> </video> </div> </template>
安卓手机中全屏播放视频,在左右会出现大概一像素的边线暴露,不能彻底覆盖屏幕。以下图github
解决方法:监听屏幕全屏事件中( video.addEventListener) 手动设置video 的left值为 0。web
问题图 | |
---|---|
![]() |
https://github.com/gnipbao/ib...
https://x5.tencent.com/tbs/gu...
http://zhaoda.net/2014/10/30/...