如果uniapp打包成apk用于安卓的话 video标签不会跟随屏幕一起滑动,会固定在屏幕上并且层级过高会挡住其他元素所以需要一个iframe标签封装成组件

<template>
  <iframe :onload="onloadCode" style="width:100%;height:100%;border:1px solid #fff;background: #000;"></iframe>
</template>
<script>
export default {
  props: {
    src: '',
  },
  data() {
    return {
      onloadCode: ''
    }
  },
  methods:{
    play(index) {
      let videoContext = uni.createVideoContext('videoId', this)
      videoContext.requestFullScreen()
    },
    //退出全屏时暂停
    fullscreenchange(e) {
      if (!e.detail.fullScreen) {
        uni.createVideoContext('videoId', this).pause();
      }
    },
  },
  created() {
    console.log(this.src)
    this.onloadCode =
        `this.contentWindow.document.body.innerHTML = '<video style="width: 100%;height: 100%"  controls :direction="90"  @play="play"  @fullscreenchange="fullscreenchange"  id="videoId"  src="${this.src}"></video>';`
  },
}
</script>
<style lang="scss">
</style>

外部引用的时候直接传入src

<nVideo v-if="tapIndex===2"  :src="imgUrl" class="nVideo"></nVideo>

原文:添加链接描述

Logo

一站式 AI 云服务平台

更多推荐