随笔 - 79, 文章 - 9, 评论 - 4, 阅读 - 22231
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

webaudiofont 移植到微信小程序

Posted on   pencilCool  阅读(133)  评论(0编辑  收藏  举报

想要把 https://github.com/surikov/webaudiofont 这个库移植 微信小程序

微信程序 npm 包的限制

https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html

如果是已经发布过的一些 npm 包,因为一些原因无法改造成小程序 npm 包的结构的话,也可以通过微调后被使用,但是请确保遵循以下几点:

小程序环境比较特殊,一些全局变量(如 window 对象)和构造器(如 Function 构造器)是无法使用的。

搞定了

image

webaudiofont 在小程序中可以使用了
https://github.com/pencilCool/mp/blob/master/OrignalMP/pages/index/webaudiofont.js

记录改造 webaudiofont 遇到的问题

不传 errfunc ,decodeAudioData 在iOS 真机上不起作用

 const errfunc = function(err) {
                        console.log("err(decodeAudioData): "+err);
    }
  audioContext.decodeAudioData(arraybuffer, function (audioBuffer) {
                          zone.buffer = audioBuffer;
   },errfunc);

atob 在IOS 上不起作用,自己实现一遍
参考: https://github.com/equicy/weapp-jwt-decode/blob/master/weapp-jwt.js

const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;

const atob = function (string) {
  string = String(string).replace(/[\t\n\f\r ]+/g, "");
  if (!b64re.test(string))
      throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");
  string += "==".slice(2 - (string.length & 3));
  var bitmap, result = "", r1, r2, i = 0;
  for (; i < string.length;) {
      bitmap = b64.indexOf(string.charAt(i++)) << 18 | b64.indexOf(string.charAt(i++)) << 12 |
          (r1 = b64.indexOf(string.charAt(i++))) << 6 | (r2 = b64.indexOf(string.charAt(i++)));
      result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255) :
          r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255) :
              String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255);
  }
  return result;
};
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示