Use HTML5 Audio if Web Audio API is not supported.

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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. :)
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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).
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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?
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Cinnamon

Veteran
Veteran
Joined
Jun 20, 2014
Messages
605
Reaction score
209
First Language
English
Primarily Uses
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?
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
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.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
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?
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
For compatibility with Windows Phone 8 (WP10 runs WebAudio fine, but 8 doesn't)
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
@Zale:

Something like this says it isn't supported:

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;}; 
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,696
Reaction score
935
First Language
English
Primarily Uses
N/A
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
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,450
Members
137,820
Latest member
georg09byron
Top