uniapp中轮播控件中video播放器不能播放等,事件失效以及video滑动不了,卡顿不顺畅(指示器切换不了)问题并且控制台报错:TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite

如题:在uniapp中轮播控件中video播放器不能播放等,事件失效的原因与解决方法:

原因: 一、首先css中的pointer-events为DOM元素的鼠标事件,值如下:

    1、auto-----默认值,鼠标事件可以穿透到设置该样式的元素,该元素的鼠标事件的触发;

    2、none-----不再监听该元素的鼠标事件,而是直接穿透鼠标事件去监听该元素的子元素的鼠标事件。

    3、其他值-----这里暂时不去说明

   二、在uniapp的轮播控件中swiper-item中的子元素(这里是video控件)被设置了样式pointer-events: none;所以导致子元素的鼠标事件失效。

解决方法:修改swiper-item中的子元素(这里是video控件)的样式:pointer-events: auto !important;

    但是这会产生第二个问题:自动切换轮播视频正常,但是手动滑动时会有:滑动不了,卡顿不顺畅(指示器切换不了)的问题并且控制台报错:

    Error in v-on handler: "TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite."

    TypeError: Failed to set the 'currentTime' property on 'HTMLMediaElement': The provided double value is non-finite.

原因:pointer-events: auto !important;开启了鼠标事件,但你手动滑动轮播的时候会触发video的滑动控制进度的事件导致报错。

解决方法::需要在video控件中设置enable-progress-gesture:'false',关闭控制进度的手势

实例:

html:
<!-- 轮播video视频 -->
            <uni-swiper-dot class="uni-swiper-dot-box" :info="dataVideo" :current="current" field="content">
              <swiper class="swiper-box" :current="swiperDotIndex">
                <swiper-item v-for="(item, index) in dataVideo" :key="index">
                  <view class="swiper-item" >
                    <video src="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/2minute-demo.mp4" controls :enable-progress-gesture="false"></video>
                  </view>
                </swiper-item>
              </swiper>
               <text class="swiper-more" @tap="goMoreSwiper">更多>></text>
            </uni-swiper-dot>


css:
.swiper-item {
  video{
      pointer-events: auto !important;
  }
}

 

posted @ 2024-04-17 10:43  逸凨  阅读(688)  评论(0编辑  收藏  举报