123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <template>
- <view class="me-video" :style="{width:width, height:height}">
-
- <video v-if="showVideo" ref="videoRef" class="video" :class="{'full-play': fullplay&&!autoplay, 'mescroll-dowload': mescrollDownLoad}" :src="src" autoplay :loop="loop" @click="videoClick" x5-playsinline="true" x5-video-player-type="h5" playsinline="true" webkit-playsinline="true" x5-video-player-fullscreen="false"></video>
-
- <view v-else class="btn-play"> <view class="triangle"></view> </view>
-
- <image v-if="(!showVideo || mescrollDownLoad) && poster" class="poster" :src="poster" @click="play()" mode="aspectFit"></image>
- </view>
- </template>
- <script>
- export default {
- props: {
- src: String,
- poster: String,
- autoplay: {
- type: Boolean,
- default(){
- return false
- }
- },
- fullplay: {
- type: Boolean,
- default(){
- return false
- }
- },
- loop: {
- type: Boolean,
- default(){
- return true
- }
- },
- width: {
- type: String,
- default: "100%"
- },
- height: {
- type: String,
- default: "225px"
- },
- mescroll: {
- type: Object,
- default(){
- return {}
- }
- }
- },
- data() {
- return {
- showVideo: this.autoplay
- }
- },
- computed: {
-
- mescrollDownLoad() {
-
- return this.mescroll.downLoadType
-
-
- return false
-
- }
- },
- watch: {
- autoplay(val) {
- if(val) this.play()
- }
- },
- methods: {
-
- play(){
- this.showVideo = true
- this.wxAutoPlay()
- },
-
- videoClick(){
-
- if(this.fullplay) this.showVideo = false
- },
-
- wxAutoPlay(){
-
-
- if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){
-
- let head = document.getElementsByTagName("head")[0]
- let wxscript = document.createElement("script");
- wxscript.type = "text/javascript"
- wxscript.src = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js"
- head.appendChild(wxscript)
- let vm = this
- let doPlay = function(){
- vm.$refs.videoRef && vm.$refs.videoRef.play()
- }
- wxscript.onload = function(){
- window.wx.config({
- debug: !1,
- appId: "",
- timestamp: 1,
- nonceStr: "",
- signature: "",
- jsApiList: []
- })
- window.wx.ready(doPlay)
- }
-
- document.addEventListener("WeixinJSBridgeReady", doPlay, false);
-
- setTimeout(()=>{
- doPlay()
- },20)
- }
-
- }
- }
- }
- </script>
- <style lang="scss">
- .me-video{
- position: relative;
- background-color: #000;
- overflow: hidden;
- // 播放按钮
- .btn-play{
- z-index: 9;
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- background-color: rgba(0,0,0,.75);
- pointer-events: none;
- .triangle{
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-25%, -50%);
- width: 0;
- height: 0;
- border-top: 16rpx solid transparent;
- border-left: 24rpx solid #fff;
- border-bottom: 16rpx solid transparent;
- }
- }
- // 封面图
- .poster{
- width: 100%;
- height: 100%;
- vertical-align: bottom;
- }
- // 视频 (默认非全屏播放)
- .video{
- z-index: 8;
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- // 全屏播放
- &.full-play{
- z-index: 999;
- position: fixed;
- }
- // 下拉时隐藏视频
- &.mescroll-dowload{
- display: none;
- }
- }
- }
- </style>
|