欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

小程序?qū)崿F(xiàn)錄音上傳功能

 更新時(shí)間:2019年11月22日 16:05:15   作者:欽晨  
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)錄音上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了小程序錄音上傳的具體代碼,供大家參考,具體內(nèi)容如下

首先我們可以先看一下微信小程序的API

這里有關(guān)于小程序錄音的一些基本配置

index.wxml:

<view class='progress_box' bindtap='openRecording' style="display:{{openRecordingdis}}">
    <view class="progress_bgs">
     <view class="progress_bg">
      <image class="progress_img" src='../../../images/SubjectInformation/luyin.png'></image>
     </view>
   </view>
</view>

index.wxss:

.topicRecording {
 float: left;
 width: 40%;
 height: 100%;
 position: relative;
}
 
 
.progress_box {
 width: 130rpx;
 height: 130rpx;
 margin-left: -65rpx;
 position: absolute;
 bottom: 0;
 left: 50%;
 display: flex;
 align-items: center;
 justify-content: center;
 background: #ccc;
 border-radius: 50%;
}
 
.progress_bgs {
 width: 114rpx;
 height: 114rpx;
 background: #fff;
 border-radius: 50%;
 margin: 9rpx;
}
 
 
.progress_bg {
 width: 106rpx;
 height: 106rpx;
 margin: 5rpx;
 position: absolute;
 background: #444;
 border-radius: 50%;
}
 
 
 
.progress_img {
 width: 82rpx;
 height: 82rpx;
 border-radius: 50%;
 margin: 12rpx;
}

index.js:

Page({
 data: {
  openRecordingdis: "block",//錄音圖片的不同
  shutRecordingdis: "none",//錄音圖片的不同
  recordingTimeqwe:0,//錄音計(jì)時(shí)
  setInter:""http://錄音名稱(chēng)
 },
 
  //錄音計(jì)時(shí)器
 recordingTimer:function(){
  var that = this;
  //將計(jì)時(shí)器賦值給setInter
  that.data.setInter = setInterval(
   function () {
    var time = that.data.recordingTimeqwe + 1;
    that.setData({
     recordingTimeqwe: time
    })
   }
   , 1000); 
 },
 
 
 //開(kāi)始錄音
 openRecording: function() {
  var that = this;
  wx.getSystemInfo({
   success: function(res) {
    that.setData({
     shutRecordingdis: "block",
     openRecordingdis: "none"
    })
   }
  })
  const options = {
   duration: 60000, //指定錄音的時(shí)長(zhǎng),單位 ms,最大為10分鐘(600000),默認(rèn)為1分鐘(60000)
   sampleRate: 16000, //采樣率
   numberOfChannels: 1, //錄音通道數(shù)
   encodeBitRate: 96000, //編碼碼率
   format: 'mp3', //音頻格式,有效值 aac/mp3
   frameSize: 50, //指定幀大小,單位 KB
  }
  //開(kāi)始錄音計(jì)時(shí)  
  that.recordingTimer();
  //開(kāi)始錄音
  recorderManager.start(options);
  recorderManager.onStart(() => {
   console.log('。。。開(kāi)始錄音。。。')
  });
  //錯(cuò)誤回調(diào)
  recorderManager.onError((res) => {
   console.log(res);
  })
 },
 
 //結(jié)束錄音
 shutRecording: function() {
  var that = this;
  wx.getSystemInfo({
   success: function(res) {
    that.setData({
     shutRecordingdis: "none",
     openRecordingdis: "block"
    })
   }
  })
  recorderManager.stop();
  recorderManager.onStop((res) => {
   console.log('。。停止錄音。。', res.tempFilePath)
   const {tempFilePath} = res;
   //結(jié)束錄音計(jì)時(shí) 
   clearInterval(that.data.setInter);
   //上傳錄音
   wx.uploadFile({
    url: appURL + '/wx_SubjectInformation/wx_SubjectRecordKeeping.do',//這是你自己后臺(tái)的連接
    filePath: tempFilePath,
    name:"file",//后臺(tái)要綁定的名稱(chēng)
    header: {
     "Content-Type": "multipart/form-data"
    },
    //參數(shù)綁定
    formData:{
     recordingtime: that.data.recordingTimeqwe,
     topicid: that.data.topicid,
     userid:1,
     praisepoints:0
    },
    success:function(ress){
     console.log(res);
     wx.showToast({
      title: '保存完成',
      icon:'success',
      duration:2000
     })
    },
    fail: function(ress){
     console.log("。。錄音保存失敗。。");
    }
   })
  })
 },
 
 //錄音播放
 recordingAndPlaying: function(eve) {
  wx.playBackgroundAudio({
   //播放地址
   dataUrl: '' + eve.currentTarget.dataset.gid + ''
  })
 },
 
})

上傳服務(wù)

@RequestMapping(value = "/wx_SubjectRecordKeeping", produces = "application/json")
 @ResponseBody
 public Object wx_SubjectRecordKeeping(HttpServletRequest request,
  @RequestParam("file") MultipartFile files, String recordingtime,
  int topicid,int userid,int praisepoints) {
 // 構(gòu)建上傳目錄路徑
 // request.getServletContext().getRealPath("/upload");
 String uploadPath = 你自己保存音頻的URL;
 // 如果目錄不存在就創(chuàng)建
 File uploadDir = new File(uploadPath);
 if (!uploadDir.exists()) {
  uploadDir.mkdir();
 }
 // 獲取文件的 名稱(chēng).擴(kuò)展名
 String oldName = files.getOriginalFilename();
 String extensionName = "";
 // 獲取原來(lái)的擴(kuò)展名
 if ((oldName != null) && (oldName.length() > 0)) {
  int dot = oldName.lastIndexOf('.');
  if ((dot > -1) && (dot < (oldName.length() - 1))) {
  extensionName = oldName.substring(dot);
  }
 }
 // 構(gòu)建文件名稱(chēng)
 String fileName = System.currentTimeMillis() + "_" + System.nanoTime()
  + extensionName;
 // 獲取
 String[] fileType = { ".CD", ".WAVE", ".AIFF", ".AU", ".MPEG", ".MP3",
  ".MPEG-4", ".MIDI", ".WMA", ".RealAudio", ".VQF", ".OggVorbis",
  ".AMR" };
 List<String> fileTyepLists = Arrays.asList(fileType);
 int fileTypeOnCount = 0;
 for (String fileTyepListss : fileTyepLists) {
  if (fileTyepListss.equalsIgnoreCase(extensionName)) {
  // -----如果是音頻文件的話(huà)
  // 構(gòu)建文件路徑
  String filePath = uploadPath + File.separator + fileName;
  // 保存文件
  try {
   FileUtils.writeByteArrayToFile(new File(filePath),
    files.getBytes());
  } catch (Exception e) {
   e.printStackTrace();
  }
  } else {
  fileTypeOnCount++;
  }
 }
 if (fileTypeOnCount == fileTyepLists.size()) {
  // 不是音頻文件
  return false;
 }
 return false;
 }

效果圖

點(diǎn)擊開(kāi)始錄音、錄完后點(diǎn)擊結(jié)束錄音

錄音成功后的返回

錄制的音頻文件

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 前端報(bào)錯(cuò)Failed?to?resolve?component:?smile-outlined?If?this?is?a?native?custom解決

    前端報(bào)錯(cuò)Failed?to?resolve?component:?smile-outlined?If?thi

    這篇文章主要為大家介紹了前端報(bào)錯(cuò)?Failed?to?resolve?component:?smile-outlined?If?this?is?a?native?custom?的問(wèn)題分析解決,有需要的朋友可以借鑒參考下
    2023-06-06
  • 微信小程序?qū)崿F(xiàn)滑動(dòng)翻頁(yè)效果(完整代碼)

    微信小程序?qū)崿F(xiàn)滑動(dòng)翻頁(yè)效果(完整代碼)

    這篇文章主要介紹了微信小程序?qū)崿F(xiàn)滑動(dòng)翻頁(yè)效果,本文通過(guò)效果圖展示實(shí)例代碼講解的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-12-12
  • postMessage消息通信Promise化的方法實(shí)現(xiàn)

    postMessage消息通信Promise化的方法實(shí)現(xiàn)

    postMessage Api 想必大家都不陌生,WebWorker 通信會(huì)用到,iframe 窗口之間通信也會(huì)用到,那么我們能不能將 postMessage 進(jìn)行一次轉(zhuǎn)化,把他變成類(lèi)似 Promise 的使用方式,所以本文給大家介紹了postMessage消息通信Promise化的方法實(shí)現(xiàn),需要的朋友可以參考下
    2024-03-03
  • 微信小程序自動(dòng)客服功能

    微信小程序自動(dòng)客服功能

    微信小程序最近比較熱,今天小編抽空做了一個(gè)客服機(jī)器人的小程序,下面小編給大家分享微信小程序自動(dòng)客服功能,需要的朋友參考下吧
    2017-11-11
  • JavaScript 數(shù)組去重詳解

    JavaScript 數(shù)組去重詳解

    下面小編就為大家?guī)?lái)一篇JavaScript數(shù)組去重的幾方法推薦。小編覺(jué)得聽(tīng)錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看
    2021-09-09
  • js隨機(jī)生成26個(gè)大小寫(xiě)字母

    js隨機(jī)生成26個(gè)大小寫(xiě)字母

    這篇文章主要為大家詳細(xì)介紹了javascript隨機(jī)生成26個(gè)大小寫(xiě)字母,感興趣的朋友可以參考一下
    2016-02-02
  • countUp.js實(shí)現(xiàn)數(shù)字動(dòng)態(tài)變化效果

    countUp.js實(shí)現(xiàn)數(shù)字動(dòng)態(tài)變化效果

    這篇文章主要為大家詳細(xì)介紹了countUp.js實(shí)現(xiàn)數(shù)字動(dòng)態(tài)變化效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • JavaScript?Echarts柱狀圖label優(yōu)化中問(wèn)題針對(duì)講解

    JavaScript?Echarts柱狀圖label優(yōu)化中問(wèn)題針對(duì)講解

    這篇文章主要介紹了JavaScript?Echarts柱狀圖label優(yōu)化中問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2022-12-12
  • vue中npm包全局安裝和局部安裝過(guò)程

    vue中npm包全局安裝和局部安裝過(guò)程

    這篇文章主要介紹了npm包全局安裝和局部安裝過(guò)程,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • JavaScript檢測(cè)鼠標(biāo)移動(dòng)方向的方法

    JavaScript檢測(cè)鼠標(biāo)移動(dòng)方向的方法

    這篇文章主要介紹了JavaScript檢測(cè)鼠標(biāo)移動(dòng)方向的方法,涉及javascript鼠標(biāo)操作的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05

最新評(píng)論