课程表

微信小程序框架

微信小程序组件

微信小程序API

微信小程序开放接口

微信小程序工具

微信小程序设计规范

工具箱
速查手册

小程序 媒体组件 video

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

视频。

属性名类型默认值说明
srcString 要播放视频的资源地址
durationNumber 指定视频时长
controlsBooleantrue是否显示默认播放控件(播放/暂停按钮、播放进度、时间)
danmu-listObject Array 弹幕列表
danmu-btnBooleanfalse是否显示弹幕按钮,只在初始化时有效,不能动态变更
enable-danmuBooleanfalse是否展示弹幕,只在初始化时有效,不能动态变更
autoplayBooleanfalse是否自动播放
bindplayEventHandle 当开始/继续播放时触发play事件
bindpauseEventHandle 当暂停播放时触发 pause 事件
bindendedEventHandle 当播放到末尾时触发 ended 事件
bindtimeupdateEventHandle 播放进度变化时触发,event.detail = {currentTime: '当前播放时间'} 。触发频率应该在 250ms 一次
objectFitStringcontain当视频大小与 video 容器大小不一致时,视频的表现形式。contain:包含,fill:填充,cover:覆盖

duration 属性在基础库版本 1.1.0 开始支持,低版本需做兼容处理
duration 属性在微信客户端 6.5.6 版本开始支持

示例代码:video标签认宽度300px、高度225px,设置宽高需要通过wxss设置width和height。

  1. <view class="section tc">
  2. <video src="{{src}}" controls ></video>
  3. <view class="btn-area">
  4. <button bindtap="bindButtonTap">获取视频</button>
  5. </view>
  6. </view>
  7. <view class="section tc">
  8. <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" danmu-list="{{danmuList}}" enable-danmu danmu-btn controls></video>
  9. <view class="btn-area">
  10. <button bindtap="bindButtonTap">获取视频</button>
  11. <input bindblur="bindInputBlur"/>
  12. <button bindtap="bindSendDanmu">发送弹幕</button>
  13. </view>
  14. </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. data: {
  16. src: '',
  17. danmuList: [
  18. {
  19. text: '第 1s 出现的弹幕',
  20. color: '#ff0000',
  21. time: 1
  22. },
  23. {
  24. text: '第 3s 出现的弹幕',
  25. color: '#ff00ff',
  26. time: 3
  27. }]
  28. },
  29. bindInputBlur: function(e) {
  30. this.inputValue = e.detail.value
  31. },
  32. bindButtonTap: function() {
  33. var that = this
  34. wx.chooseVideo({
  35. sourceType: ['album', 'camera'],
  36. maxDuration: 60,
  37. camera: ['front','back'],
  38. success: function(res) {
  39. that.setData({
  40. src: res.tempFilePath
  41. })
  42. }
  43. })
  44. },
  45. bindSendDanmu: function () {
  46. this.videoContext.sendDanmu({
  47. text: this.inputValue,
  48. color: getRandomColor()
  49. })
  50. }
  51. })

video

相关api:wx.createVideoContext

Bug & Tip

  1. tip: 请勿在 scroll-view 中使用 video 组件
转载本站内容时,请务必注明来自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号