限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。

小程序

小程序实例 | 视频播放加弹幕效果

js Page({ onReady(res) { this.videoContext = wx.createVideoContext('myVideo') }, inputValue: '', data: { src: '', danmuList: [ // { // text: '第 1s 出现的弹幕', // color: '#ff0000', // t

作者
王明昌
发布时间
小程序实例 | 视频播放加弹幕效果 js
Page({
  onReady(res) {
    this.videoContext = wx.createVideoContext('myVideo')
  },
  inputValue: '',
  data: {
    src: '',
    danmuList: [
      // {
      //   text: '第 1s 出现的弹幕',
      //   color: '#ff0000',
      //   time: 1
      // },
      // {
      //   text: '第 3s 出现的弹幕',
      //   color: '#ff00ff',
      //   time: 3
      // }
      ]
  },
  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },
  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: '#ccc'
    })
  }
})
wxml

  
  
    
    
  
wxss
/* pages/video/index.wxss */
#myVideo{
  width: 100%
}
0/500
友善分享您的看法。
反馈邮箱