微信小程序媒体组件video视频,微信小程序视频组件库
本文摘要
video 视频。 属性名 类型 默认值 说明 最低版本 src String
video
视频。
| 属性名 | 类型 | 默认值 | 说明 | 最低版本 |
|---|---|---|---|---|
| src | String | 要播放视频的资源地址 | ||
| duration | Number | 指定视频时长 | 1.1.0 | |
| controls | Boolean | true | 是否显示默认播放控件(播放/暂停按钮、播放进度、时间) | |
| danmu-list | Object Array | 弹幕列表 | ||
| danmu-btn | Boolean | false | 是否显示弹幕按钮,只在初始化时有效,不能动态变更 | |
| enable-danmu | Boolean | false | 是否展示弹幕,只在初始化时有效,不能动态变更 | |
| autoplay | Boolean | false | 是否自动播放 | |
| loop | Boolean | false | 是否循环播放 | 1.4.0 |
| muted | Boolean | false | 是否静音播放 | 1.4.0 |
| bindplay | EventHandle | 当开始/继续播放时触发play事件 | ||
| bindpause | EventHandle | 当暂停播放时触发 pause 事件 | ||
| bindended | EventHandle | 当播放到末尾时触发 ended 事件 | ||
| bindtimeupdate | EventHandle | 播放进度变化时触发,event.detail = {currentTime: '当前播放时间'} 。触发频率应该在 250ms 一次 | ||
| bindfullscreenchange | EventHandle | 当视频进入和退出全屏是触发,event.detail = {fullScreen: '当前全屏状态'} | 1.4.0 | |
| objectFit | String | contain | 当视频大小与 video 容器大小不一致时,视频的表现形式。contain:包含,fill:填充,cover:覆盖 | |
| poster | String | 默认控件上的音频封面的图片资源地址,如果 controls 属性值为 false 则设置 poster 无效 |
video标签认宽度300px、高度225px,设置宽高需要通过wxss设置width和height。
示例代码:
view class="section tc">
video src="{{src}}" controls >video>
view class="btn-area">
button bindtap="bindButtonTap">获取视频button>
view>
view>
view class="section tc">
video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownloadfilekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" danmu-list="{{danmuList}}" enable-danmu danmu-btn controls>video>
view class="btn-area">
button bindtap="bindButtonTap">获取视频button>
input bindblur="bindInputBlur"/>
button bindtap="bindSendDanmu">发送弹幕button>
view>
view>
function getRandomColor () {
let rgb = []
for (let i = 0 ; i 3; ++i){
let color = Math.floor(Math.random() * 256).toString(16)
color = color.length == 1 '0' + color : color
rgb.push(color)
}
return '#' + rgb.join('')
}
Page({
onReady: function (res) {
tShopfas.videoContext = wx.createVideoContext('myVideo')
},
inputValue: '',
data: {
src: '',
danmuList: [
{
text: '第 1s 出现的弹幕',
color: '#ff0000',
time: 1
},
{
text: '第 3s 出现的弹幕',
color: '#ff00ff',
time: 3
}]
},
bindInputBlur: function(e) {
tShopfas.inputValue = e.detail.value
},
bindButtonTap: function() {
var that = tShopfas
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: ['front','back'],
success: function(res) {
that.setData({
src: res.tempFilePath
})
}
})
},
bindSendDanmu: function () {
tShopfas.videoContext.sendDanmu({
text: tShopfas.inputValue,
color: getRandomColor()
})
}
})
相关api:wx.createVideoContext
Bug & Tip
-
tip:video组件是由客户端创建的原生组件,它的层级是最高的。 -
tip: 请勿在scroll-view中使用video组件。 -
tip:css动画对video组件无效。
第二部分:如何开通一个小商店
相关文章
****更多行业产品开发方案,请关注 加速度JSUDO***
<以上资讯仅供参考,如果您需解决具体问题,建议您关注作者;如果有软件产品开发需求,可在线咨询加速度产品经理获取方案和报价>
加速度JSUDO是一家企业级数字化解决方案提供商,专注于软件开发、网络营销、数字化转型咨询及云计算服务。核心业务包括定制化ERP/CRM系统、快速应用开发、大数据分析及物联网(IoT)解决方案,助力企业提升效率与智能化水平。服务覆盖制造业、零售、物流等多行业,致力于通过技术创新推动客户数字化转型。
添加客服微信获取更多内容










