小程序video的各种事件 如何让小程序视频只播放前五秒

小程序video的各种事件 如何让小程序视频只播放前五秒,第1张

imeUpdate: function (e) {

      //实时播放进度 秒数

        var currentTime = parseInt(e.detail.currentTime)

        console.log("视频播放到第" + currentTime + "秒")//查看正在播放时间,以秒为单位

        if(currentTime>300){

          let videoContext = wx.createVideoContext('myVideo', this)

          console.log(videoContext)

          videoContext.pause

          念消videoContext.seek("1")

          videoContext.pause

          wx.showModal({

            title: '充值提示',

              content: "非会员只能看前五分钟的内容",//提示内容

              confirmColor: '#2EA7E0',//确定按钮的颜色

    胡高仔          showCancel: false,//不显示取消按钮

               success (res) {

              if (res.confirm) {

                 console.log('用户点击确定按钮')

               } else if (res.cancel) {

                 console.log('用户点击取消按钮')

               }

             }

            })

        }

   裤汪 },

<video  bindtimeupdate="timeUpdate"  id="myVideo" src="{{kino_mazmuni.info.resource_url}}"  initial-time="{{kino_mazmuni.duration_time}}" title="{{kino_mazmuni.info.video_name}}" object-fit="fill"  enable-auto-rotation="true" vslide-gesture="true"  enable-play-gesture="true" auto-pause-if-navigate="true"  show-screen-lock-button="true"  duration="15"   enable-auto-rotation="true" duration="true" show-fullscreen-btn  show-casting-button="true"   autoplay="true"  poster='https://apqak.alkuyi.com/alkuyi_video_poster.png' objectFit="cover" class="bofangqi">

1.默认显示封面

2.一个视频播放的时候,其他视频停止播放,并显示封面。

1.通过wx:if判断当前视频是否是播放的状态,如果是就显示视频,如果不是就隐藏视频;

2.点击封面的时候,获取到该视频的id,进行判断,如果当前没有视频播放,就把该视频设置为播放的状态;如果当前有视频播放,则停止当前播放的视频,再播放你点击的这个视频。

<view class="video_body">

            <view wx:for="{{courseList}}" wx:for-item="course" class='course-pannle-item' wx:for-index="idx" wx:key="index">

                <view class='video-item'>

                    <video class="video" wx:if='{{idx==playIndex}}' id='video{{idx}}' autoplay='{{true}}' show-center-play-btn="{{false}}" src='{{course.videoUrl}}' controls="羡孙庆true" objectFit="cover"></video>

                    <image class='video-cover video' wx:if='{{idx!=playIndex}}' mode='widthFix' src='{{course.coverUrl}}'></image>

                    <image class='video-play-btn' wx:if='{{idx!=playIndex}}' mode='widthFix' data-index='{{idx}}' bindtap='videoPlay' src='/images/home/btn.png'></image>

                    <!-- <text wx:if='{{idx!=playIndex}}' class='video-duration fs-28'>

                            {{course.duration}}

           凯尺             </text>-->

                </view>

            </view>

        </view>

 data: {

    playIndex: null, //用于记录当前播放的视频的索引值

    courseList: [

      {

        videoUrl: 'https://fxmv3-asset.oss-cn-zhangjiakou.aliyuncs.com/132a004191990de6d1dde6379a56987b.mp4'兄握, //视频路径

        coverUrl: '/images/home/1.png', //视频封面图

        duration: '03:00' //视频时长

      },

      {

        videoUrl: 'https://fxmv3-asset.oss-cn-zhangjiakou.aliyuncs.com/bddfba680554409e47aeb653ec5d58af.mp4',

        coverUrl: '/images/home/2.png',

        duration: '04:45'

      }

    ]

  },

 videoPlay: function (e) {

      var curIdx = e.currentTarget.dataset.index

      // 没有播放时播放视频

    if (!this.data.playIndex) {

         this.setData({

           playIndex: curIdx

        })

       var videoContext = wx.createVideoContext('video' + curIdx)//这里对应的视频id

     videoContext.play()

   } else {

       // 有播放时先将prev暂停,再播放当前点击的current

      var videoContextPrev = wx.createVideoContext('video' + this.data.playIndex)

       if (this.data.playIndex != curIdx) {

        videoContextPrev.pause()

       }

        this.setData({

         playIndex: curIdx

         })

       var videoContextCurrent = wx.createVideoContext('video' + curIdx)

       videoContextCurrent.play()

     }

    },


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12394424.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存