Skip to content

Commit b6cbce4

Browse files
committed
Audio Optimization
Audio doesn't recreate the play function, and instead uses the stored reference
1 parent 9646f30 commit b6cbce4

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

nightly/zepyhr.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ PIXI.Zephyr = {
7575
useAudio: () => {
7676
PIXI.Audio.ctx = new AudioContext();
7777
PIXI.Audio.buffers = new Map();
78+
PIXI.Audio.player = function () {
79+
if (PIXI.Audio.buffers.has(this.src)) {
80+
let aud = PIXI.Audio.ctx.createBufferSource();
81+
aud.buffer = PIXI.Audio.buffers.get(this.src);
82+
aud.connect(PIXI.Audio.ctx.destination);
83+
aud.start(0);
84+
}
85+
}
7886
PIXI.Audio.from = (src) => {
7987
let r = new XMLHttpRequest();
8088
r.open('GET', src, true);
@@ -89,14 +97,7 @@ PIXI.Zephyr = {
8997
r.send();
9098
return {
9199
src: src,
92-
play: () => {
93-
if (PIXI.Audio.buffers.has(src)) {
94-
let aud = PIXI.Audio.ctx.createBufferSource();
95-
aud.buffer = PIXI.Audio.buffers.get(src);
96-
aud.connect(PIXI.Audio.ctx.destination);
97-
aud.start(0);
98-
}
99-
}
100+
play: PIXI.Audio.player
100101
}
101102
}
102103
},
@@ -176,4 +177,4 @@ PIXI.utils.requestFullScreen = (view) => {
176177
window.addEventListener('contextmenu', (e) => {
177178
e.preventDefault();
178179
})
179-
console.log("%cUsing " + PIXI.Zephyr.version + "! https://github.com/OttCS/ZephyrJS", "text-decoration: none;border-radius: 4px;margin: 4px 0;padding: 4px;color: #EF6F6C;border: 2px solid #EF6F6C;");
180+
console.log("%cUsing " + PIXI.Zephyr.version + "! https://github.com/OttCS/ZephyrJS", "color: #EF6F6C;");

0 commit comments

Comments
 (0)