当前位置:   article > 正文

uniapp使用录音_uniapp录音

uniapp录音
  1. <template>
  2. <view class="WH">
  3. <u--form :model="formData" :rules="rules" ref="uForm" labelPosition="left" labelWidth="110px" class="width paddingL40 paddingLR32 bgWhite text-right-form">
  4. <u-form-item label="录音:" borderBottom>
  5. <view class="viaTion">
  6. <view v-for="(item, index) in soundsList" :key="index" style="display: flex">
  7. <text @click="playVoice(item)">
  8. {{ item.fileName }}
  9. </text>
  10. <view class="icon_close" @click="soundClose(item, index)"> </view>
  11. </view>
  12. <nb-voice-record v-if="soundsList && soundsList.length < 9" @startRecord="start" @endRecord="end" @cancelRecord="cancel"></nb-voice-record>
  13. </view>
  14. </u-form-item>
  15. </u--form>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. formData: {},
  23. soundsList: [],
  24. rules: {}
  25. };
  26. },
  27. mounted() {},
  28. methods: {
  29. //播放录音
  30. playVoice(item) {
  31. let _this = this;
  32. if (item.filePath) {
  33. const failAudio = uni.createInnerAudioContext();
  34. failAudio.src = this.$http.config.baseUrl + "/preview/" + item.filePath;
  35. failAudio.play();
  36. }
  37. },
  38. //删除录音
  39. soundClose(item, index) {
  40. this.soundsList.splice(index, 1);
  41. },
  42. // 开始录音
  43. start() {},
  44. // 结束录音并处理得到的录音文件
  45. // event中,app端仅有tempFilePath字段,微信小程序还有duration和fileSize两个字段
  46. end(event) {
  47. this.sounds = event;
  48. //发送录音:
  49. return new Promise((resolve, reject) => {
  50. let url = "";
  51. // #ifdef APP-PLUS
  52. url = this.$http.config.baseUrl + "/api/file/fileUpOne";
  53. // #endif
  54. // #ifdef H5
  55. url = "/api/file/fileUpOne";
  56. // #endif
  57. let a = uni.uploadFile({
  58. url: url,
  59. filePath: event.tempFilePath,
  60. name: "file",
  61. formData: {
  62. user: "test",
  63. },
  64. success: (res) => {
  65. setTimeout(() => {
  66. let a = JSON.parse(res.data);
  67. this.soundsList.push(a.data);
  68. }, 1000);
  69. },
  70. fail: function () {},
  71. });
  72. });
  73. },
  74. // 用户取消录音
  75. cancel() {},
  76. },
  77. };
  78. </script>
  79. <style lang="scss">
  80. .viaTion {
  81. display: flex;
  82. flex-direction: column;
  83. align-items: flex-start;
  84. }
  85. </style>

下载插件    很全面的~

nbVoiceRecord长按录音动画组件,多端权限判断,可监听开始、结束、取消事件 - DCloud 插件市场

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/899924
推荐阅读
相关标签
  

闽ICP备14008679号