微信小程序停止其他视频播放当前视频的实例代码

所属分类: 网络编程 / JavaScript 阅读数: 1010
收藏 0 赞 0 分享

微信小程序停止其他视频播放当前视频,代码如下所示:

<view class="content">
 <!--首页-->
 <scroll-view class='nav-page'>
  <view class="item-box " wx:for="{{videelsi}}" wx:key="item">
   <!-- 标题层 -->
   <!-- 视频图片层 -->
   <view data-id="{{index}}" class="video-image-box" style="display: {{ _index == index ? 'none' : 'block' }};" bindtap="videoPlay">
    <view class="video-cover-box">
     <image class="video-image" src="{{item.cover}}" mode="aspectFit">
     </image>
    </view>
    <!-- 视频按钮 -->
    <image class="video-image-play" src="../image/vidoe.png" mode="scaleToFill"></image>
   </view>

   <!-- 视频播放层 -->
   <video enable-progress-gesture show-play-btn src="{{item.src}}" data-id="{{index}}" class='video' wx:if="{{_index == index}}" objectFit='contain' autoplay='true' controls></video>
   <cover-view style="display: {{ _index == index ? 'none' : 'block' }};" class="video-title-box">
    <cover-view class='video-title'>{{item.title}}</cover-view>
   </cover-view>
  </view>
 </scroll-view>

</view>`

css 样式

.content {
 border-top: transparent 1px solid;
 box-sizing: border-box;
 /* height: 100%; */
 width: 100%;
 padding: 0 20rpx;
}
.container{
 border-top: transparent 1px solid;
 /* box-sizing: border-box; */
 /* height: 100%; */
 width: 100%;
}
view {
 vertical-align:middle;
}
.item-box {
 width: 100%;
 margin-top: 40rpx;
 position: relative;
}
.video-title-box{
 height: 70rpx;
 width: 100%;
 background:rgba(0,0,0,1);
opacity:0.2;
 position: absolute;
 bottom: 10rpx;
}
.video-title{
 text-align: center;
 font-size: 30rpx;
 line-height: 70rpx;
font-weight:400;
color:rgba(255,255,255,1);
}
.item-box{
 width: 100%;
 display: -webkit-box; 
 -webkit-box-orient: vertical;
 -webkit-line-clamp:2;
 overflow: hidden;
 text-overflow:ellipsis;
}

.item-box .video-image-box {
 height: 400rpx;
 width: 100%;
 background-repeat: no-repeat;
 background-size: 100% 100%;
 background-position-x: 30rpx;
 position: relative;
}

.video-cover-box{
 height: 100%;
 width: 100%;
 text-align: center;
 line-height: 0rpx;
}
.item-box:first-of-type{
 margin-top: 0rpx;
}
.item-box .video-image-box .video-cover-box .video-image {
 height: 100%;
 width: 100%;
}

.item-box .video {
 height: 300rpx;
 width: 100%;
 margin: 0 30rpx 0 0;
 position: relative;
}

.item-box .video-image-box .video-image-play {
 position: absolute;
 width: 80rpx;
 height: 80rpx;
 top: calc(50% - 40rpx);
 left: calc(50% - 40rpx);
 z-index: 100;
}

js  代码

const app = getApp()

Page({
 data: {
  videoPlay: null,
  videelsi: [],
 },
 onLoad: function () {
  wx.hideShareMenu()
  this.vidoelist()
 },
 vidoelist() {
  app.api.getData(app.data.https + 'wechat/farm/index').then(res => {
   console.log(res)
   this.setData({
    videelsi: res.data.list
   })
  })
 },
 // 点击cover播放,其它视频结束
 videoPlay: function (e) {
  var _index = e.currentTarget.dataset.id
  this.setData({
   _index: _index
  })
  //停止正在播放的视频
  var videoContextPrev = wx.createVideoContext(_index + "")
  videoContextPrev.stop();

  setTimeout(function () {
   //将点击视频进行播放
   var videoContext = wx.createVideoContext(_index + "")
   videoContext.play();
  }, 500)
 }
})

以上所述是小编给大家介绍的微信小程序停止其他视频播放当前视频,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

更多精彩内容其他人还在看

深入解析Vue 组件命名那些事

本篇文章主要介绍了深入解析Vue 组件命名那些事,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue学习笔记进阶篇之vue-cli安装及介绍

这篇文章主要介绍了Vue学习笔记进阶篇之vue-cli安装及介绍,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

jquery版轮播图效果和extend扩展

这篇文章主要为大家详细介绍了jquery版轮播图效果,以及extend扩展的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

jQuery Validate格式验证功能实例代码(包括重名验证)

本文通过实例代码给大家介绍了jQuery Validate格式验证功能,代码中包括重名验证的方法,需要的的朋友参考下吧
收藏 0 赞 0 分享

Angular.js中angular-ui-router的简单实践

本篇文章主要介绍了Angular.js中angular-ui-router的简单实践,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

JavaScript实现二维坐标点排序效果

这篇文章主要为大家详细介绍了JavaScript实现二维坐标点排序效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

深入理解vue2.0路由如何配置问题

本篇文章主要介绍了vue2.0路由配置问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

基于bootstrap实现多个下拉框同时搜索功能

这篇文章主要为大家详细介绍了基于bootstrap实现多个下拉框同时搜索功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

JavaScript 值类型和引用类型的初次研究(推荐)

这篇文章主要介绍了JavaScript 值类型和引用类型的初次研究,需要的朋友可以参考下
收藏 0 赞 0 分享

利用jQuery异步上传文件的插件用法详解

这篇文章主要介绍了利用jQuery异步上传文件的插件用法详解,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多