類似于微博視頻播放的功能,簡(jiǎn)單寫(xiě)了一個(gè)小demo欺嗤,測(cè)試可以正常執(zhí)行。功能是當(dāng)點(diǎn)擊一個(gè)視頻播放完成后卫枝,自動(dòng)加載下一個(gè)視頻煎饼,當(dāng)所有視頻全部加載完成后,視頻播放停止校赤。
wxml:
JS:
const app = getApp()
var that
var getData = require('../../../utils/util.js')
Page({
? data: {
? ? teachingVideoList: [],//視頻集合
? ? index: 1,//下標(biāo)
? ? src: 'https://cos.ap-beijing.myqcloud.com/teachingVideo/enterElook.mp4' //默認(rèn)加載的第一個(gè)視頻
? },
? onLoad: function () {
? ? that = this
? ? wx.request({
? ? ? url: app.data.serverUrl + 'upload_queryTeachingVideo.action',
? ? ? success: function (res) {
? ? ? ? that.setData({
? ? ? ? ? teachingVideoList: res.data.teachingVideoList,
? ? ? ? })
? ? ? }
? ? })
? },
? onReady: function (res) {
? ? this.videoContext = wx.createVideoContext('myVideo')//視頻管理組件
? },
? videoEnd: function (res) { ? // 視頻播放結(jié)束后執(zhí)行的方法
? ? var that = this
? ? if (that.data.index == that.data.teachingVideoList.length-1) {
? ? ? wx.showToast({
? ? ? ? title: '已播放完成',
? ? ? ? icon: 'loading',
? ? ? ? duration: 2500,
? ? ? ? mask: true,
? ? ? })
? ? ? that.setData({
? ? ? ? index: 1
? ? ? })
? ? ? this.videoContext.pause() ?//暫停
? ? }else{
? ? getData.alertWait('播放下一個(gè)視頻', that.videoPlay())
? ? }
? },
? videoPlay: function () {
? ? that = this
? ? var videolLength = that.data.teachingVideoList.length;
? ? that.setData({
? ? ? index: that.data.index + 1,
? ? ? src: that.data.teachingVideoList[that.data.index][1],
? ? })
? ? this.videoContext.autoplay =='true'//設(shè)置自動(dòng)播放
? ? this.videoContext.play()//播放視頻
? }
})