jjw

写给自己的博客。 记录学习的点滴以备查。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

本地文件播放

Posted on 2020-11-08 21:53  jjw  阅读(79)  评论(0编辑  收藏  举报
          async    play() {
                let upload = document.getElementById("file1");
                let f = upload.files[0];
              var ctx = new AudioContext();
                var source = ctx.createBufferSource();
        var data = f.slice(0);
        let v = await data.arrayBuffer();
        console.log(v);

        ctx.decodeAudioData(v).then(function (decodeData) {
          source.buffer = decodeData;
          source.connect(ctx.destination);
          source.start(0);
        });