欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

微信小程序-實(shí)現(xiàn)錄制視頻(附部分代碼) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >

微信小程序-實(shí)現(xiàn)錄制視頻(附部分代碼)

發(fā)表時(shí)間:2020-9-23

發(fā)布人:葵宇科技

瀏覽次數(shù):143

項(xiàng)目中,需要客戶錄制一段視頻,上傳到服務(wù)器,找了很久,終于實(shí)現(xiàn)了這個(gè)功能。微信小程序有兩種方式可以實(shí)現(xiàn)錄制視頻。

1.使用相機(jī)的CameraContext.startRecord
2.使用官方API:wx.chooseVideo
方法一
wxml

<view class="video">
  <camera wx:if="{{videoSrc.length === 0}}" device-position="font" flash="off" binderror="error" style="width: {{cameraWidth}}px;height: 442rpx;">
  </camera>
  <video style="width: {{cameraWidth}}px; height: 442rpx;" wx:else src="{{videoSrc}}" controls></video>
</view>
  <view class="btn" id='btn-photo' bindtouchstart="handleTouchStart" bindtouchend="handleTouchEnd" bindlongpress="handleLongPress">按住錄制</view>

js部分代碼

  onLoad: function (options) {
    //調(diào)用設(shè)置相機(jī)大小的方法
    this.setCameraSize();
    this.ctx = wx.createCameraContext();
  },
  /**
   * 獲取系統(tǒng)信息 設(shè)置相機(jī)的大小適應(yīng)屏幕
   */
  setCameraSize() {
    //獲取設(shè)備信息
    const res = wx.getSystemInfoSync();
    //獲取屏幕的可使用寬高,設(shè)置給相機(jī)
    this.setData({
      cameraHeight: res.windowHeight,
      cameraWidth: res.windowWidth
    })
    console.log(res)
  },
  /**
   * 開始錄像的方法
   */
  startShootVideo() {
    this.setData({
      videoSrc: ''
    })
    console.log("========= 調(diào)用開始錄像 ===========")
    let that = this
    this.ctx.startRecord({
      timeoutCallback: () => {
      },
      success: (res) => {
      },
      fail() {
        wx.showToast({
          title: '錄像失敗',
          icon: 'none',
          duration:4000
        })
        console.log("========= 調(diào)用開始錄像失敗 ===========")
      }
    })
  },
  /**
   * 結(jié)束錄像
   */
  stopShootVideo() {
    wx.hideLoading();
    // console.log("========= 調(diào)用結(jié)束錄像 ===========")
    this.ctx.stopRecord({
      compressed: true, //壓縮視頻
      success: (res) => {
        console.log(res)
        this.setData({
          videoSrc: res.tempVideoPath
        })
      },
      fail() {
        wx.showToast({
          title: '錄像失敗',
          icon: 'none',
          duration:4000
        })
        console.log("========= 調(diào)用結(jié)束錄像失敗 ===========")
      }
    })
  },

  //touch start 手指觸摸開始
  handleTouchStart: function (e) {
    this.setData({
      startTime: e.timeStamp
    })
  },

  //touch end 手指觸摸結(jié)束
  handleTouchEnd: function (e) {
    // wx.hideLoading();
    let endTime = e.timeStamp;
    //判斷是點(diǎn)擊還是長按 點(diǎn)擊不做任何事件,長按 觸發(fā)結(jié)束錄像
    if (endTime - this.data.startTime > 350) {
      //長按操作 調(diào)用結(jié)束錄像方法
      this.stopShootVideo();
    } else {
      this.setData({
        textFlag: ''
      })
    }

  },

  /**
   * 長按按鈕進(jìn)行錄像
   */
  handleLongPress: function (e) {
    // 長按方法觸發(fā),調(diào)用開始錄像方法
    this.startShootVideo();
  },

注:由于官方限制,只能錄制30秒。

方法二
在js中

wx.chooseVideo({
  sourceType: ['album','camera'],
  maxDuration: 60,
  camera: 'back',
  success(res) {
    console.log(res.tempFilePath)
  }
})

使用wx.chooseVideo拍攝視頻或從手機(jī)相冊(cè)中選視頻,拍攝界面不能自定義。
如果有什么不清楚的地方,歡迎私信哦.
具體參數(shù)說明請(qǐng)參考官方文檔
https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseVideo.html(鏈接地址)



作者:IU憨憨
鏈接:https://www.jianshu.com/p/1fdbe12ce477
來源:簡(jiǎn)書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請(qǐng)注明出處。

相關(guān)案例查看更多