Skip to content

Commit

Permalink
fix: audio
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanzm committed Dec 5, 2023
1 parent 75ea2be commit 280a6db
Show file tree
Hide file tree
Showing 6 changed files with 3,207 additions and 42 deletions.
17 changes: 17 additions & 0 deletions playable-adapter/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"wx": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {}
}
42 changes: 24 additions & 18 deletions playable-adapter/dist/playable-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,32 +382,38 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ });
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);

var hasWarn = false;
function fixCreateInnerAudioContext() {
var originApi = wx.createInnerAudioContext;
Reflect.defineProperty(wx, 'createInnerAudioContext', {
value: function () {
var innerAudio = originApi();
var ownProp = Object.getOwnPropertyNames(innerAudio);
var audioProto = Object.getPrototypeOf(innerAudio);
var srcDesc;
if (ownProp.includes('src')) {
srcDesc = Reflect.getOwnPropertyDescriptor(innerAudio, 'src');
// 获取原有属性的描述符
var originalDescriptor = Object.getOwnPropertyDescriptor(innerAudio, 'src');
/**
* 低版本的试玩基础库音频实例的属性是不能通过 Object.defineProperty 重定义的
* 高版本基础库修复了这个问题,因此针对低版本基础库做一个提示
*/
if (!originalDescriptor.configurable) {
console.error("[playable-adapter]: \u5F53\u524D\u57FA\u7840\u5E93\u97F3\u9891\u4E0D\u53EF\u9002\u914D\uFF0C\u8BF7\u624B\u52A8\u7ED9\u97F3\u9891\u7684src\u52A0\u4E0A\u72EC\u7ACB\u5206\u5305\u7684\u524D\u7F00".concat(_config__WEBPACK_IMPORTED_MODULE_0__["default"].userPathPrefix, "!"));
}
else {
srcDesc = Reflect.getOwnPropertyDescriptor(audioProto, 'src');
}
var audioProxy = new Proxy({}, {
set: function (t, p, v, r) {
if (p === 'src') {
v = _config__WEBPACK_IMPORTED_MODULE_0__["default"].userPathPrefix + v;
Object.defineProperty(innerAudio, 'src', {
get: function () {
return originalDescriptor.get.call(this);
},
set: function (value) {
// 如果已经手动加过前缀了,不需要重复添加
if (value.indexOf(_config__WEBPACK_IMPORTED_MODULE_0__["default"].userPathPrefix) === -1) {
originalDescriptor.set.call(this, _config__WEBPACK_IMPORTED_MODULE_0__["default"].userPathPrefix + value);
}
else {
originalDescriptor.set.call(this, value);
}
}
return Reflect.set(innerAudio, p, v, innerAudio);
},
get: function (t, p, r) {
return Reflect.get(innerAudio, p, innerAudio);
}
});
return audioProxy;
});
}
return innerAudio;
},
configurable: true,
});
Expand Down
Loading

0 comments on commit 280a6db

Please sign in to comment.