300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 微信小程序官方组件展示之媒体组件video源码

微信小程序官方组件展示之媒体组件video源码

时间:2021-03-06 11:44:38

相关推荐

微信小程序官方组件展示之媒体组件video源码

以下将展示微信小程序之媒体组件video源码官方组件能力,组件样式仅供参考,开发者可根据自身需求定义组件样式,具体属性参数详见小程序开发文档。

功能描述:

视频(v2.4.0 起支持同层渲染)。

属性说明:

Bug & Tip

1.tip:`video 默认宽度 300px、高度 225px,可通过 wxss 设置宽高。

2.tip:从 2.4.0 起 video 支持同层渲染,更多请参考原生组件使用限制

3.tip: 若当前组件所在的页面或全局开启了 enablePassiveEvent 配置项,该内置组件可能会出现非预期表现(详情参考 enablePassiveEvent 文档)

支持的格式

支持的编码格式

小窗特性说明

video 小窗支持以下三种触发模式(在组件上设置 picture-in-picture-mode 属性):

1.push 模式,即从当前页跳转至下一页时出现小窗(页面栈push)

2.pop 模式,即离开当前页面时触发(页面栈pop)

3.以上两种路由行为均触发小窗

此外,小窗还支持以下特性:

1.小窗容器尺寸会根据原组件尺寸自动判断

2.点击小窗,用户会被导航回小窗对应的播放器页面

3.小窗出现后,用户可点击小窗右上角的关闭按钮或调用 context.exitPictureInPicture() 接口关闭小窗

当播放器进入小窗模式后,播放器所在页面处于 hide 状态(触发 onHide 生命周期),该页面不会被销毁。当小窗被关闭时,播放器所在页面会被 unload (触发 onUnload 生命周期)。

DRM加密播放

1.小程序开发者获取到 DRM 加密的 视频地址、身份认证 url、license url

2.使用 video 标签将以上几个参数填入

3.小程序确认该 video 为 DRM 视频源,进行 DRM 设备身份认证并且获取播放许可证

4.设备身份认证通过并获取播放许可证之后,由 DRM 底层进行解密播放

示例代码

JAVASCRIPT

function getRandomColor() {const rgb = []for (let i = 0; i < 3; ++i) {let color = Math.floor(Math.random() * 256).toString(16)color = color.length === 1 ? '0' + color : colorrgb.push(color)}return '#' + rgb.join('')}Page({onShareAppMessage() {return {title: 'video',path: 'page/component/pages/video/video'}},onReady() {this.videoContext = wx.createVideoContext('myVideo')},onHide() {},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 = thiswx.chooseVideo({sourceType: ['album', 'camera'],maxDuration: 60,camera: ['front', 'back'],success(res) {that.setData({src: res.tempFilePath})}})},bindVideoEnterPictureInPicture() {console.log('进入小窗模式')},bindVideoLeavePictureInPicture() {console.log('退出小窗模式')},bindPlayVideo() {console.log('1')this.videoContext.play()},bindSendDanmu() {this.videoContext.sendDanmu({text: this.inputValue,color: getRandomColor()})},videoErrorCallback(e) {console.log('视频错误信息:')console.log(e.detail.errMsg)}})

WXML

<view class="page-body"><view class="page-section tc"><video id="myVideo" src="http://wxsnsdy./105/0/snsdyvideodownload?filekey=3028010421301f090402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c01042530230204136ffd93020457e3c4ff02024ef31e8d7f02030f42400204045a320a000400" binderror="videoErrorCallback" danmu-list="{{danmuList}}" enable-danmu danmu-btn show-center-play-btn='{{false}}' show-play-btn="{{true}}" controlspicture-in-picture-mode="{{['push', 'pop']}}"bindenterpictureinpicture='bindVideoEnterPictureInPicture'bindleavepictureinpicture='bindVideoLeavePictureInPicture'></video><view style="margin: 30rpx auto" class="weui-label">弹幕内容</view><input bindblur="bindInputBlur" class="weui-input" type="text" placeholder="在此处输入弹幕内容" /><button style="margin: 30rpx auto" bindtap="bindSendDanmu" class="page-body-button" type="primary" formType="submit">发送弹幕</button><navigator style="margin: 30rpx auto" url="picture-in-picture" hover-class="other-navigator-hover"><button type="primary" class="page-body-button" bindtap="bindPlayVideo">小窗模式</button></navigator></view></view>

版权声明: 本站所有内容均由互联网收集整理、上传,如涉及版权问题,请联系我们第一时间处理。

原文链接地址:https://developers./miniprogram/dev/component/live-player.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。