溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序如何停止其他視頻播放當(dāng)前視頻

發(fā)布時間:2021-07-20 14:10:20 來源:億速云 閱讀:190 作者:小新 欄目:web開發(fā)

這篇文章主要介紹了微信小程序如何停止其他視頻播放當(dāng)前視頻,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

微信小程序停止其他視頻播放當(dāng)前視頻,代碼如下所示:

<view class="content">
 <!--首頁-->
 <scroll-view class='nav-page'>
  <view class="item-box " wx:for="{{videelsi}}" wx:key="item">
   <!-- 標(biāo)題層 -->
   <!-- 視頻圖片層 -->
   <view data-id="{{index}}" class="video-image-box"  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  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播放,其它視頻結(jié)束
 videoPlay: function (e) {
  var _index = e.currentTarget.dataset.id
  this.setData({
   _index: _index
  })
  //停止正在播放的視頻
  var videoContextPrev = wx.createVideoContext(_index + "")
  videoContextPrev.stop();

  setTimeout(function () {
   //將點擊視頻進(jìn)行播放
   var videoContext = wx.createVideoContext(_index + "")
   videoContext.play();
  }, 500)
 }
})

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“微信小程序如何停止其他視頻播放當(dāng)前視頻”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI