时间:2019-05-05 来源:小程序工厂
娇***:
你好,方便给个代码片段?我们定位下问题
张***:
部分代码如下
.wxml
......
.js
// pages/chapter/chapter.js
const app = getApp()
const TAG = "PageChapter"
var utils = require('../../utils/util.js')
const videoUrl = require('../../config').videoUrl
Page({
/**
* 页面的初始数据
*/
data: {
hasLoadSuccess: false,
vid: "",
videoPoster: "../../res/video_poster.png",
videoUrl: null,
videoInitialTime: 0, //当前视频初始播放时间
currentPlayRate: 1.0,
playRateItems: [{
index: "0",
value: "0.8倍",
checked: false,
rate: 0.8
},
{
index: "1",
value: "1.0倍",
checked: true,
rate: 1.0
},
{
index: "2",
value: "1.5倍",
checked: false,
rate: 1.5
},
],
autoPlay: true,
},
//播放倍速选择
playRateRadioChange: function (event) {
utils.log(event);
var index = Number(event.detail.value);
var playRateItems = this.data.playRateItems;
for (var i = 0, len = playRateItems.length; i < len; i++) {
if (index == i) {
playRateItems[i].checked = true;
try {
var currentPlayRate = playRateItems[i].rate;
if (this.videoContext) {
this.videoContext.playbackRate(Number(currentPlayRate));
wx.showToast({
icon: "success",
title: playRateItems[i].value + '速播放',
duration: 2000
})
this.setData({
currentPlayRate: currentPlayRate
})
}
} catch (e) {
utils.log(e);
wx.showModal({
title: '提示',
content: '倍速播放失败 请稍候再试哦',
showCancel: false,
confirmText: "确定"
})
}
} else {
playRateItems[i].checked = false;
}
}
this.setData({
playRateItems: playRateItems
})
},
//视频播放回调
videoPlay: function (event) {
utils.log(event)
var currentPlayRate = this.data.currentPlayRate;
if (this.videoContext) {
this.videoContext.playbackRate(currentPlayRate);
}
},
//视频暂停回调
videoPause: function (event) {
utils.log(event)
},
//视频观看时间更新回调
videoTimeUpdate: function (event) {
utils.log(event)