99 lines
2.4 KiB
JavaScript
99 lines
2.4 KiB
JavaScript
|
|
/**
|
|
* Web唐明明
|
|
* 一个梦想做木雕手艺人的程序员
|
|
* explain: videoSwiper
|
|
*/
|
|
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
videoList: {
|
|
type : Array,
|
|
value : []
|
|
},
|
|
playId : {
|
|
type : Number,
|
|
value : 0
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
controls: false,
|
|
showPlay: false,
|
|
isPlay : true
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
// 视频滚动了
|
|
changeVideo(e){
|
|
let videoLists = this.data.videoList,
|
|
current = e.detail.current,
|
|
currentId = this.data.playId,
|
|
prevId = videoLists[current].video_id
|
|
|
|
// 停止老
|
|
let videoContextCurrent = wx.createVideoContext("video" + currentId, this)
|
|
videoContextCurrent.stop()
|
|
|
|
// 播放新
|
|
let videoContextPrev = wx.createVideoContext("video" + prevId, this)
|
|
videoContextPrev.play()
|
|
|
|
this.setData({
|
|
isPlay: true,
|
|
playId: prevId
|
|
})
|
|
},
|
|
|
|
//视频播放控件
|
|
videoPlay(e){
|
|
let videoId = e.currentTarget.dataset.videoid,
|
|
videoContext = wx.createVideoContext("video" + videoId, this),
|
|
isPlayState = this.data.isPlay
|
|
|
|
if(isPlayState){
|
|
videoContext.pause()
|
|
}else{
|
|
videoContext.play()
|
|
}
|
|
|
|
this.setData({
|
|
isPlay : !isPlayState
|
|
})
|
|
|
|
|
|
// let videoId,
|
|
// priorId = this.data.playId
|
|
|
|
// if(e.type == "tap"){
|
|
// // 点击播放视频
|
|
// videoId = "video" + e.currentTarget.dataset.videoid
|
|
// // 实例化video
|
|
// let videoContext = wx.createVideoContext(videoId)
|
|
// // 播放视频
|
|
// videoContext.play()
|
|
|
|
// wx.showToast({
|
|
// title: "播放",
|
|
// icon : "none"
|
|
// })
|
|
// }else{
|
|
// // 滑动切换视频
|
|
// videoId = e
|
|
// }
|
|
|
|
// console.log("当前的:", videoId)
|
|
// console.log("上一个:", priorId)
|
|
}
|
|
}
|
|
})
|