课程表

微信小程序框架

微信小程序组件

微信小程序API

微信小程序开放接口

微信小程序工具

微信小程序设计规范

工具箱
速查手册

小程序 视频组件控制

当前位置:免费教程 » 移动开发 » 微信小程序

wx.createVideoContext(videoId)

创建并返回 video 上下文 videoContext 对象

videoContext

videoContext 通过 videoId 跟一个 video 组件绑定,通过它可以操作一个 video 组件。

videoContext对象的方法列表:

方法参数说明
play播放
pause暂停
seekposition跳转到指定位置,单位 s
sendDanmudanmu发送弹幕,danmu 包含两个属性 text, color。

示例代码:

  1. <view class="section tc">
  2. <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" enable-danmu danmu-btn controls></video>
  3. <view class="btn-area">
  4. <input bindblur="bindInputBlur"/>
  5. <button bindtap="bindSendDanmu">发送弹幕</button>
  6. </view>
  7. </view>
  1. function getRandomColor () {
  2. let rgb = []
  3. for (let i = 0 ; i < 3; ++i){
  4. let color = Math.floor(Math.random() * 256).toString(16)
  5. color = color.length == 1 ? '0' + color : color
  6. rgb.push(color)
  7. }
  8. return '#' + rgb.join('')
  9. }
  10. Page({
  11. onReady: function (res) {
  12. this.videoContext = wx.createVideoContext('myVideo')
  13. },
  14. inputValue: '',
  15. bindInputBlur: function(e) {
  16. this.inputValue = e.detail.value
  17. },
  18. bindSendDanmu: function () {
  19. this.videoContext.sendDanmu({
  20. text: this.inputValue,
  21. color: getRandomColor()
  22. })
  23. }
  24. })
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号