Use HTML5 Audio if Web Audio API is not supported.

Could someone please write me a small plugin that forces the use of HTML5 Audio if Web Audio API is not supported?

I see approximately where it has to be done but I can't get it right.

Thank you so much. 🙂
I'm looking into making this, but it's unfortunately more complicated than just a few lines. The Html5Audio class supplied by RPG Maker MV only supports one audio tag, because it's only intended to be used for bgm. To make Html5Audio a viable fallback if Web Audio isn't available, we'll have to rewrite the Html5Audio class to support multiple elements, which will take more time and testing to finish. I suppose I could work on it, though I'm not sure how much time I'd need it.

The only situation in which you'd really need this is if you're playing your game in Internet Explorer, as it doesn't support the Web Audio API, or, like in this situation (For those that don't know, they had a previous topic with the issue, looking for support), it isn't supported on Windows XP (which, coincidentally, isn't supported by the engine to begin with).
I'm looking into making this, but it's unfortunately more complicated than just a few lines. The Html5Audio class supplied by RPG Maker MV only supports one audio tag, because it's only intended to be used for bgm. To make Html5Audio a viable fallback if Web Audio isn't available, we'll have to rewrite the Html5Audio class to support multiple elements, which will take more time and testing to finish. I suppose I could work on it, though I'm not sure how much time I'd need it.

The only situation in which you'd really need this is if you're playing your game in Internet Explorer, as it doesn't support the Web Audio API, or, like in this situation (For those that don't know, they had a previous topic with the issue, looking for support), it isn't supported on Windows XP (which, coincidentally, isn't supported by the engine to begin with).
Ah, that's a shame. Guess I'll just have to remove Windows XP from the compatibility list. We're releasing on Steam next Friday.

Any chance I can help you code an Html5Audio class to function as a replacement for Web Audio? If it's a simple copy & paste job, or if I can look at Web Audio and copy that, maybe I can try.

Actually I don't understand why Html5 is only available for BGM. Then how do SEs, BGS, etc. play on Android or devices that don't have Web Audio support?
Ah, that's a shame. Guess I'll just have to remove Windows XP from the compatibility list. We're releasing on Steam next Friday.

Any chance I can help you code an Html5Audio class to function as a replacement for Web Audio? If it's a simple copy & paste job, or if I can look at Web Audio and copy that, maybe I can try.

Actually I don't understand why Html5 is only available for BGM. Then how do SEs, BGS, etc. play on Android or devices that don't have Web Audio support?
Please have the tester running on Windows XP to try again with this plugin. It's kind of makeshift and rushed a bit, but with my testing it was working out alright. The only issue I had with this is that BGSs looped slightly oddly, like there was a gap between it looping, but I did not notice the same thing for BGM. This plugin should also allow Internet Explorer to play web games alright, so I suppose I might still work on and maintain this plugin, but so far I have not decided.

It will show the audio tag in the DOM when a sound is played, though I believe this isn't necessary (The audio can play without doing this), but I figured that it wasn't going to hurt too much to have them displayed. If you want, I can make it a parameter for whether or not they are displayed. In order to not clutter up the DOM, the tags are automatically removed as the audio it would play is no longer needed (such as sound effects, or bgm after you change it).

Please let me know if you have any issues with it.
Omg!! So fast! Thank you so much!

I had one betatester try it out and it worked for him/her. Fingers crossed this is a universal fix. 🙂  

Thanks again!

Btw, by DOM do you mean the log that shows up if you hit F8?
Btw, by DOM do you mean the log that shows up if you hit F8?
Not the log, no. The DOM is the Document Object Model, and is the way your web page is structured. When you press F8 and go to the Elements tab, that's pretty much the DOM, it shows you all the HTML tags on your page, what order they're in, and such. I originally had some issues with the Html5 audio not saying that it had finished loading into the game, so I thought that maybe it was because the audio tags weren't in the DOM, but it was actually caused by something else. I realized that around the time I was posting the plugin for you, but decided to leave it as it is for now. If it works for you, then it's doing its job, so there's no need to change it, currently. Like I said, if you have issues with it later on, please just let me know so I can look into fixing them.
I also found out that Web Audio API isn't fully supported. I tried to do a sample Audio Crossfade plugin and it tells me the web audio isn't supported.
Oh, I hadn't seen this thread. I'm also interested in using HTML5 audio, so I guess I may help with something if there's anything left to be done?
I also found out that Web Audio API isn't fully supported. I tried to do a sample Audio Crossfade plugin and it tells me the web audio isn't supported.
What is "it" that said WebAudio wasn't supported?

Oh, I hadn't seen this thread. I'm also interested in using HTML5 audio, so I guess I may help with something if there's anything left to be done?
I think that it should be ok. What I basically did was just copy the Html5Audio class, and pop a '.prototype' on ever Html5Audio.<whatever> bit, and then I had to change the AudioManager a bit to accommodate the change, since it didn't expect there to be instances of Html5Audio. May I ask why you were thinking about using Html5Audio instead of WebAudio?
For compatibility with Windows Phone 8 (WP10 runs WebAudio fine, but 8 doesn't)
@Zale:

Something like this says it isn't supported:

Spoiler
Code:
var CrossfadeSample = {};CrossfadeSample.play = function() {  try {    context = new webkitAudioContext();    this.gainNode = context.createGainNode();  }  catch(e) {    alert("Web Audio API is not supported in this browser");  }  bufferLoader = new BufferLoader(context, [      "sounds/organ-echo-chords.wav",      "sounds/blueyellow.wav"  ], finishedLoading);  bufferLoader.load();  var ctx = this;  function finishedLoading(bufferList) {    // Create two sources.    ctx.ctl1 = createSource(bufferList[0]);    ctx.ctl2 = createSource(bufferList[1]);    // Mute the second source.    ctx.ctl2.gainNode.gain.value = 0;    // Start playback in a loop    ctx.ctl1.source.noteOn(0);    ctx.ctl2.source.noteOn(0);    // Set the initial crossfade to be just source 1.    ctx.crossfade(0);  }  function createSource(buffer) {    var source = context.createBufferSource();    var gainNode = context.createGainNode();    source.buffer = buffer;    // Turn on looping    source.loop = true;    // Connect source to gain.    source.connect(gainNode);    // Connect gain to destination.    gainNode.connect(context.destination);    return {      source: source,      gainNode: gainNode    };  }};CrossfadeSample.stop = function() {  this.ctl1.source.noteOff(0);  this.ctl2.source.noteOff(0);};// Fades between 0 (all source 1) and 1 (all source 2)CrossfadeSample.crossfade = function(element) {  var x = parseInt(element.value) / parseInt(element.max);  // Use an equal-power crossfading curve:  var gain1 = 0.5 * (1.0 + Math.cos(x * Math.PI));  var gain2 = 0.5 * (1.0 + Math.cos((1.0 - x) * Math.PI));  this.ctl1.gainNode.gain.value = gain2;  this.ctl2.gainNode.gain.value = gain2;}; 
context = new webkitAudioContext(); this.gainNode = context.createGainNode();

Funny, I was just reading about this yesterday. you see, NwJS uses Chrome 41. Support for "webkitAudioContext" was dropped after chrome 36m. You just need to drop the webkit prefix. 

Source

Original thread: https://forums.rpgmakerweb.com/threads/use-html5-audio-if-web-audio-api-is-not-supported.52393/