123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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}` : color
- rgb.push(color)
- }
- return `#${rgb.join('')}`
- }
- Page({
- onShareAppMessage() {
- return {
- title: 'video',
- path: 'packageComponent/pages/media/video/video'
- }
- },
- onReady() {
- this.videoContext = wx.createVideoContext('myVideo')
- },
- onHide() {
- },
- inputValue: '',
- data: {
- theme: 'light',
- enableAutoRotation: true,
- 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
- })
- }
- })
- },
- bindVideoEnterPictureInPicture() {
- console.log('进入小窗模式')
- },
- bindVideoLeavePictureInPicture() {
- console.log('退出小窗模式')
- },
- bindPlayVideo() {
- this.videoContext.play()
- },
- bindSendDanmu() {
- this.videoContext.sendDanmu({
- text: this.inputValue,
- color: getRandomColor()
- })
- },
- videoErrorCallback(e) {
- console.log('视频错误信息:')
- console.log(e.detail.errMsg)
- },
- handleSwitchChange(e) {
- this.setData({
- enableAutoRotation: e.detail.value
- })
- },
- onLoad() {
- this.setData({
- theme: wx.getSystemInfoSync().theme || 'light'
- })
- if (wx.onThemeChange) {
- wx.onThemeChange(({theme}) => {
- this.setData({theme})
- })
- }
- }
- })
|