>  기사  >  php教程  >  WeChat 애플릿 vidao는 비디오 재생 및 공격 기능을 실현합니다.

WeChat 애플릿 vidao는 비디오 재생 및 공격 기능을 실현합니다.

高洛峰
高洛峰원래의
2016-12-08 09:52:553100검색

WeChat 애플릿은 Vidao 비디오 재생 및 사격 기능을 구현합니다.

vidao

지금 보는 공식 문서에는 이전에는 단무 속성이 있었지만 지금은 이 속성이 적용됩니다. 비디오 상태를 제어하려면 비디오 태그의 고유 ID를 기반으로 객체 인스턴스를 얻을 수 있습니다. 비디오 구성 요소에는 작업 속성이 없으며 작업을 통해 제어할 수 없습니다.

.wxml

<view class="section tc">
 <video src="{{src}}"  controls ></video>
 <view class="btn-area">
  <button bindtap="bindButtonTap">获取视频</button>
 </view>
</view>
 
<!--
 danmu-list:弹幕列表
 enable-danmu:是否显示弹幕
 danmu-btn:弹幕按钮
 controls:是否显示视频控件,并没有什么用
 -->
<view class="section tc">
 <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" binderror="videoErrorCallback" 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>
 
<!-- 现在的video就下面三个属性 -->
<video src="" binderror="" hidden></video>

.js

function getRandomColor () {
 let rgb = []
 for (let i = 0 ; i < 3; ++i){
  let color = Math.floor(Math.random() * 256).toString(16)
  color = color.length == 1 ? &#39;0&#39; + color : color
  rgb.push(color)
 }
 return &#39;#&#39; + rgb.join(&#39;&#39;)
}
 
Page({
 onReady: function (res) {
  this.videoContext = wx.createVideoContext(&#39;myVideo&#39;)
 },
 inputValue: &#39;&#39;,
  data: {
    src: &#39;&#39;,
  danmuList: [
   {
    text: &#39;第 1s 出现的弹幕&#39;,
    color: &#39;#ff0000&#39;,
    time: 1
   },
   {
    text: &#39;第 3s 出现的弹幕&#39;,
    color: &#39;#ff00ff&#39;,
    time: 3
   }
  ]
  },
 bindInputBlur: function(e) {
  this.inputValue = e.detail.value
 },
  bindButtonTap: function() { //视频下载
    var that = this
    wx.chooseVideo({
      sourceType: [&#39;album&#39;, &#39;camera&#39;],
      maxDuration: 60,
      camera: [&#39;front&#39;,&#39;back&#39;],
      success: function(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },
 bindSendDanmu: function () {
  this.videoContext.sendDanmu({
   text: this.inputValue,
   color: getRandomColor()
  })
 },
  videoErrorCallback: function(e) {
   console.log(&#39;视频错误信息:&#39;);
   console.log(e.detail.errMsg);
  }
})

효과

WeChat 애플릿 vidao는 비디오 재생 및 공격 기능을 실현합니다.


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.