Comments (8)
Why is your build replacing new XMLHttpRequest
with new Object
?
from sound.
Because Facebook doesn't like the "XMLHttpRequest" string, so we replace it like that.
from sound.
In order to convert base64 string to an arraybuffer, you can do that without XMLHttpRequest. For instance: https://stackoverflow.com/a/21797381
The hacky solution is to override _loadUrl
to have it just work.
A better option is to just pass the ArrayBuffer to the sound library:
import { sound } from '@pixi/sound';
import url from './mysound.mp3';
const arrayBuffer = base64toArrayBuffer(url);
sound.add('mysound', arrayBuffer);
from sound.
Thanks for the example.
I tried like the code above, asset is loaded but when I try to play sound I get error like
Here is my load function;
loadSound(key, src, json, callback) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
const arrayBuffer = decode(src);
sound.add(key, arrayBuffer);
console.log(arrayBuffer);
sound._sounds[key].addSprites(json.spritemap);
console.log(sound._sounds[key]);
callback();
}
from sound.
I don't know that it is important or not but when I console the arrayBuffer with delay, the byteLength of it is 0.
from sound.
This worked for me:
https://codesandbox.io/s/pixijs-sound-base64-example-vj6xcj?file=/src/index.ts
from sound.
After adding the line
const data = str.split(",").slice(1).join(",");
It is working for me too. Thank you so much.
from sound.
Yeah you need to chop off the mime type and just interpret the data. Glad it works!
from sound.
Related Issues (20)
- Play on Sound with unfinished preload leads to an additional preload call ending in a double buffer assignment HOT 4
- PixiJS Deprecation Warning: Loader.registerPlugin() is deprecated, use extensions.add() instead. Deprecated since v6.5.0 HOT 1
- Sound Library not stopping paused Sounds on stop all
- Does the new @pixi/assets loader support loading sounds? HOT 2
- Version 5 error HOT 2
- Problem with dependencies v5.0.0 HOT 1
- Assets Loader with Sound should use the exact order of the audio formats defined HOT 2
- Format fallback with different filename bases HOT 1
- v4.x doesn't respect `utils.supported`, which loads everything in `utils.extensions` anyway HOT 2
- Bug: Failed to set the 'buffer' HOT 4
- undefined is not an object (evaluating 'this.find(t).play') HOT 1
- Sound is suspended while window loses focus HOT 6
- `disableAutoPause` doesn't disable auto-resume HOT 4
- Sound does not work well on some browsers on iOS HOT 4
- Parser for Pixi Assets does not register properly HOT 2
- Uncaught TypeError just by following the Tutorial HOT 2
- Calling .stop() on a sound whilst the browser window is blurred does not actually stop the sound HOT 3
- Sine tone generated is one octave too low
- [bug] HTMLAudioInstance.ts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sound.