Skip to content

Use object notation in library_sdl.js. NFC #23028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2762,11 +2762,13 @@ var LibrarySDL = {

if (bytes !== undefined && SDL.webAudioAvailable() && canPlayWithWebAudio) {
audio = undefined;
webAudio = {};
// The audio decoding process is asynchronous, which gives trouble if user code plays the audio data back immediately
// after loading. Therefore prepare an array of callback handlers to run when this audio decoding is complete, which
// will then start the playback (with some delay).
webAudio.onDecodeComplete = []; // While this member array exists, decoding hasn't finished yet.
webAudio = {
// The audio decoding process is asynchronous, which gives trouble if user
// code plays the audio data back immediately after loading. Therefore
// prepare an array of callback handlers to run when this audio decoding
// is complete, which will then start the playback (with some delay).
onDecodeComplete: [], // While this member array exists, decoding hasn't finished yet.
}
var onDecodeComplete = (data) => {
webAudio.decodedBuffer = data;
// Call all handlers that were waiting for this decode to finish, and clear the handler list.
Expand Down Expand Up @@ -2815,8 +2817,7 @@ var LibrarySDL = {
}

if (SDL.webAudioAvailable()) {
webAudio = {};
webAudio.decodedBuffer = buffer;
webAudio = { decodedBuffer: buffer };
} else {
audio = new Audio();
audio.mozAudioChannelType = 'content'; // bugzilla 910340
Expand Down Expand Up @@ -2873,13 +2874,14 @@ var LibrarySDL = {
var audio;
if (info.webAudio) {
// Create an instance of the WebAudio object.
audio = {};
audio.resource = info; // This new object is an instance that refers to this existing resource.
audio.paused = false;
audio.currentPosition = 0;
// Make our instance look similar to the instance of a <media> to make api simple.
audio.play = function() { SDL.playWebAudio(this); }
audio.pause = function() { SDL.pauseWebAudio(this); }
audio = {
resource: info, // This new object is an instance that refers to this existing resource.
paused: false,
currentPosition: 0,
play() { SDL.playWebAudio(this); },
pause() { SDL.pauseWebAudio(this); },
};
} else {
// We clone the audio node to utilize the preloaded audio buffer, since
// the browser has already preloaded the audio file.
Expand Down Expand Up @@ -2964,12 +2966,13 @@ var LibrarySDL = {
var audio;
if (info.webAudio) { // Play via Web Audio API
// Create an instance of the WebAudio object.
audio = {};
audio.resource = info; // This new webAudio object is an instance that refers to this existing resource.
audio.paused = false;
audio.currentPosition = 0;
audio.play = function() { SDL.playWebAudio(this); }
audio.pause = function() { SDL.pauseWebAudio(this); }
audio = {
resource: info, // This new webAudio object is an instance that refers to this existing resource.
paused: false,
currentPosition: 0,
play() { SDL.playWebAudio(this); },
pause() { SDL.pauseWebAudio(this); },
};
} else if (info.audio) { // Play via the <audio> element
audio = info.audio;
}
Expand Down