0

问题描述

在<scroll>中加入多个视频和音频(多媒体文件是通过后台传来的文件地址和后缀判断属于哪个类型,for+if添加进dom的),better-scoll的touchstart导致音频和视频没有办法按播放按钮图片描述

问题出现的环境背景及自己尝试过哪些方法

配置中click是true。。试着remove监听事件,但是报错了。。试着添加@ontouchStart来控制音频播放,但是这样按音量键也会控制播放,而且多个音频也没法用flag来控制播放与暂停

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
以下是部分页面代码

    <div class="survey-detail">
      <scroll class="list-survey" v-show="!showOver" :data="object" :mouseWheel="mouseWheel">
        <div class="survey-detail-wrapper">
           <div class="survey-detail-header" v-if="itemDetail.questionnaire">
          </div>
          <div class="survey-detail-content">
            <ul>
              <li v-for="(item, index) in object" :key="index" class="li-item">
                <p class="answer-bottom title" :class="{'choice':item.requiredFlag}">{{index + 1}}、{{item.subject}} <span class="answer-type">({{type[item.type-1]}})</span>
                  <br/>
                  <img :src="mediaUrl + item.mediaAttachment.realpath" v-if="item.hasOwnProperty('mediaAttachment') && (item.mediaAttachment.extend.toLowerCase() =='jpg'|| item.mediaAttachment.extend.toLowerCase()=='jpeg' || item.mediaAttachment.extend.toLowerCase()=='png')" style="width: 70%;">
                  <video :src="mediaUrl + item.mediaAttachment.realpath" v-if="item.hasOwnProperty('mediaAttachment') && (item.mediaAttachment.extend.toLowerCase() == 'mp4' || item.mediaAttachment.extend.toLowerCase() == 'rmvb' || item.mediaAttachment.extend.toLowerCase() == 'avi' || item.mediaAttachment.extend.toLowerCase() =='wma' || item.mediaAttachment.extend.toLowerCase() == '3gp' || item.mediaAttachment.extend.toLowerCase() =='mov' ||item.mediaAttachment.extend.toLowerCase() == 'webm')" controls="controls" style="width: 70%;" controlsList="nodownload" oncontextmenu="return false"></video>
                  <audio :src="mediaUrl + item.mediaAttachment.realpath" v-if="item.hasOwnProperty('mediaAttachment') && (item.mediaAttachment.extend.toLowerCase() =='mp3'|| item.mediaAttachment.extend.toLowerCase()=='ape' || item.mediaAttachment.extend.toLowerCase()=='flac')" style="width:90%" controls="controls"  controlsList="nodownload" oncontextmenu="return false"></audio>
                </p>
           

以下是better-scroll代码

<template>
  <div ref="wrapper">
    <slot></slot>
  </div>
</template>

<script >
import BScroll from 'better-scroll'

export default {
  props: {
    probeType: {
      type: Number,
      default: 1
    },
    click: {
      type: Boolean,
      default: true
    },
    tap: {
      type: Boolean,
      default: true
    },
    listenScroll: {
      type: Boolean,
      default: false
    },
    data: {
      type: Array,
      default: null
    },
    pullup: {
      type: Boolean,
      default: true
    },
    pulldown: {
      type: Boolean,
      default: true
    },
    // 开启鼠标滚轮事件
    mouseWheel: {
      type: Boolean,
      default: false
    },
    beforeScroll: {
      type: Boolean,
      default: false
    },
    refreshDelay: {
      type: Number,
      default: 20
    }
  },
  mounted() {
    setTimeout(() => {
      this._initScroll()
    }, 20)
  },
  methods: {
    _initScroll() {
      if (!this.$refs.wrapper) {
        return
      }
      this.scroll = new BScroll(this.$refs.wrapper, {
        probeType: this.probeType,
        click: this.click,
        mouseWheel: this.mouseWheel
      })
      if (this.listenScroll) {
        let me = this
        this.scroll.on('scroll', (pos) => {
          me.$emit('scroll', pos)
        })
      }
      // 上拉加载
      if (this.pullup) {
        this.scroll.on('scrollEnd', () => {
          if (this.scroll.y <= (this.scroll.maxScrollY + 50)) {
            this.$emit('scrollToEnd')
          }
        })
      }
      // 下拉刷新
      if (this.pulldown) {
        this.scroll.on('touchEnd', (pos) => {
          // 下拉动作
          if (pos.y > 50) {
            this.$emit('pulldown')
          }
        })
      }

      if (this.beforeScroll) {
        this.scroll.on('beforeScrollStart', () => {
          this.$emit('beforeScroll')
        })
      }
    },
    disable() {
      this.scroll && this.scroll.disable()
    },
    enable() {
      this.scroll && this.scroll.enable()
    },
    refresh() {
      this.scroll && this.scroll.refresh()
    },
    scrollTo() {
      this.scroll && this.scroll.scrollTo.apply(this.scroll, arguments)
    },
    scrollToElement() {
      this.scroll && this.scroll.scrollToElement.apply(this.scroll, arguments)
    }
  },
  watch: {
    data() {
      setTimeout(() => {
        this.refresh()
      }, this.refreshDelay)
    }
  }
}
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">

</style>
     

你期待的结果是什么?实际看到的错误信息又是什么?

Vince 3
2018-09-04 提问
1 个回答
0

尝试用音频视频插件可是把问题弄的好复杂,最后的最后我放弃了better-scroll。

撰写答案

推广链接