这是wxml
<view class="section tc">
<video id="myVideo" style="height:{{videoHeight}}px;width:{{videoWidth}}px" controls="false" autoplay="true" src="voice/5.mp4" binderror="videoErrorCallback" danmu-list="{{danmuList}}" controls>
</video>
</view>
这是js
onLoad: function(options) {
var _this = this;
//获取屏幕宽高
_this.setData({
userInfo: app.globalData.user
})
wx.getSystemInfo({
success: function(res) {
var windowWidth = res.windowWidth;
//video标签认宽度300px、高度225px,设置宽高需要通过wxss设置width和height。
var videoHeight = (225 / 300) * windowWidth //屏幕高宽比
console.log('videoWidth: ' + windowWidth)
console.log('videoHeight: ' + videoHeight)
_this.setData({
videoWidth: windowWidth,
videoHeight: videoHeight
})
}
})
var that = this;
wx.request({
url: "http://localhost:8080/Examination_System_war_exploded/wxadmin/wxshowTeacher",
// data: { 'page': pagenum },
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
_this.setData({
video: res.data.teacherlist
})
console.log(res.data)
// video[123].USERNAME
},
fail: function(res) {
console.log(".....fail.....");
}
})
},
//点击视频
onclick:function(event){
this.setData({
arr: event.currentTarget.id
})
this.videoContext.play()
},
bindInputBlur: function(e) {
this.inputValue = e.detail.value
},
bindSendDanmu: function() {
if (this.data.isRandomColor) {
var color = getRandomColor();
} else {
var color = this.data.numberColor;
}
this.videoContext.sendDanmu({
text: this.inputValue,
color: color
})
},
videoErrorCallback: function(e) {
console.log('视频错误信息:')
console.log(e.detail.errMsg)
},