<template>
  <view>
    <button type="default" @click="audio2dataURL()">播放</button>
  </view>
</template>
<script>
  export default {
    data() {
      return {
        
      }
    },
    onShow() {
      // this.bofang()
      // this.audio2dataURL()
    },
    methods: {
      bofang(){
        const innerAudioContext = uni.createInnerAudioContext();
        innerAudioContext.autoplay = true;
        innerAudioContext.src = 'https://bjetxgzv.cdn.bspapp.com/VKCEYUGU-hello-uniapp/2cc220e0-c27a-11ea-9dfb-6da8e309e0d8.mp3';
        innerAudioContext.onPlay(() => {
          console.log('开始播放');
        });
        innerAudioContext.onError((res) => {
          console.log(res.errMsg);
          console.log(res.errCode);
        });
      },
      audio2dataURL() {
        console.log('----------audio2dataURL-----------')
        let path="/storage/emulated/0/DCIM/Camera/60054701923172203.mp3"
          plus.io.resolveLocalFileSystemURL(path, function(entry){  
              entry.file(function(file){  
                  var reader = new plus.io.FileReader();  
                  reader.readAsDataURL(file);  
                  reader.onloadend = function (e) {  
              console.log('----------语音转换结果------------')
                      console.log(e.target.result);  
              // 这里websoket发送
              // self.sendMsg(e.target.result)
              // console.log('----------发送语音完成------------')
                  };  
              },function(e){  
            console.log("读写出现异常: " + e.message)
              })  
          })  
      },
    }
  }
</script>
<style>
</style>