Jump to content

Audio Issue with BABYLON.Sound


_ElementoZerO_
 Share

Recommended Posts

Hello to all!

I'm trying to add some sound to my little game using :

var ambientWind = new BABYLON.Sound("ambientWind", "./assets/audio/wind01.mp3", this.GameKernel.scene, null, { loop: true, autoplay: false });

i'm get this error:

Uncaught (in promise) TypeError: Failed to execute 'decodeAudioData' on 'AudioContext': parameter 1 is not of type 'ArrayBuffer'

I already tried to fallow this : link

No errors but still not audio...

Then i'm tried with jQuery .ready().. nothing...

I'm using BabylonJs latest preview version 

Any suggestions?

Link to comment
Share on other sites

Hello,

the code is very big and split in various js if you want i can send you in private, i'm using bracket with chrome browser, but is very strange because after using .wav now also .mp3 (the same) seems work..unbelievable..

I tried to drag and drop the .mp3 file in chrome and work.

I think at this point that is the preview function of bracket, unfortunately before the issue i don't try with xamp..

Link to comment
Share on other sites

@_ElementoZerO_ -

Are you certain that the MP3 file actually does work now, as I often find that when elemets suddenly appear to work when they did not previously, it is often an illusion. Just make certain that the MP3 file is actually working and not simply playing the WAV file in your browser cache - as reloading your scene doesn't clean cache (depending on your broeser and settings), and you very well might be drawing the conclusion that your MP3 file is playing when it is actually playing the same name WAV file from memory since most browsers are set up to function by file name first, and file format secondly. 

DB

Link to comment
Share on other sites

On 19/6/2016 at 8:29 PM, dbawel said:

@_ElementoZerO_ -

Are you certain that the MP3 file actually does work now, as I often find that when elemets suddenly appear to work when they did not previously, it is often an illusion. Just make certain that the MP3 file is actually working and not simply playing the WAV file in your browser cache - as reloading your scene doesn't clean cache (depending on your broeser and settings), and you very well might be drawing the conclusion that your MP3 file is playing when it is actually playing the same name WAV file from memory since most browsers are set up to function by file name first, and file format secondly. 

DB

ok today i work on my notebook with linux and again the same problem so maybe is the os? because i use linux mint on notebook and windows 10 on Desktop at home, now will try with windows 10 and .

(now that i think is probably the china usb card..because my onboard card  is broken..)

EDIT:

ok under windows all work correctly despite the china usb audio card..so at this point i think is a problem bounded to alsamixer

when i get home will try with opensuse on desktop and will update.

EDIT2:

ok on opensuse work too, so at this point is my notebook linux that have same problem. Thank you to all for the help ^^

Link to comment
Share on other sites

  • 1 month later...
On 6/20/2016 at 1:10 AM, _ElementoZerO_ said:

ok today i work on my notebook with linux and again the same problem so maybe is the os? because i use linux mint on notebook and windows 10 on Desktop at home, now will try with windows 10 and .

(now that i think is probably the china usb card..because my onboard card  is broken..)

EDIT:

ok under windows all work correctly despite the china usb audio card..so at this point i think is a problem bounded to alsamixer

when i get home will try with opensuse on desktop and will update.

EDIT2:

ok on opensuse work too, so at this point is my notebook linux that have same problem. Thank you to all for the help ^^

I'm working with a visualization and can't get either mp3 or wav to work on Mint. The same page plays on Ubuntu, strangely enough. And Chromebook.

I notice it won't work on Android Chrome either.

*EDIT*

It may be this:

http://stackoverflow.com/questions/12587977/html5-audio-chrome-on-android-doesnt-automatically-play-song-vs-chrome-on-pc-d

https://bugs.chromium.org/p/chromium/issues/detail?id=138132

So, Android Chrome does not allow autoplay in HTML5 audio.  All the results I'm getting are around 2012, 2013, but Im pretty sure it applies, and there are no "hey guess what you can do now". Not sure what the reasoning is here. Pretty lame for HTML5 game dev. 

Going to put a control button in and see if it plays then.

 

**EDIT**

@_ElementoZerO_  Try opening update manager, running all your updates, then restart. I got it to work on Mint/Chromium at least

 

 

Link to comment
Share on other sites

No PG is hard to see what's wrong. I look at your line of code, you use autoplay: false. Do you use play() after.

var ambientWind = new BABYLON.Sound("ambientWind", "./assets/audio/wind01.mp3", this.GameKernel.scene, null, { loop: true, autoplay: false });
ambientWind.play();

 

Link to comment
Share on other sites

 

Babylon.sound seems to dislike the way i update my players positions (multiplayer),

 

so personally i'm using html5 audio player instead,

example; 

Html.

<audio id="ambientBackground01" src="assets/sounds/ambientBackground01.mp3" loop></audio>

Javascript.

window.onload = function() {
//fix for autoplay 
document.getElementById('ambientBackground01').play();

/* variable example..
var au = document.getElementById('ambientBackground01');
au.play();
au.pause();
au.volume += 0.1;
*/

};

 

quick n easy, but ofc it doesn't have the same features as you can get with babylon sound :) 

 

Link to comment
Share on other sites

@Nabroski has provided the essential step to playing HTML media on any OS, device, browsr, etc. If you have any questions about specific behaviors for an OS, device, or browser, I have tested most all thoroughly for HTML media. but s mentioned, the key step is to load the media before playing. Also, as several users have mentioned, autoplay() is enabled on some OS and not on others. And you will not be able to use the autoplay option to make the media autoplay, and play(), pause(), and other HTML media functions won't work as you might expect within WebGL.

The only way to use video and audio media in WebGL, is to first understand that you must use HTML nodes, and then must first load the media into memory (not simply assigning a variable), and then either the OS will initialize autoplay, or not - depending on the OS. And if autoplay is not initialized natively such as on Android and/or Ipad, then the user must trigger a play() function through an event or other method so that the video/audio begins to play; as even though the media has been loaded, it will not buffer without the user initializing play manually.

The only other essential info the developer must know is that once the media is loaded and either the browser or user initializes play (depending on the OS), the method to access any HTML media attributes and properties is to call these using the DOM functions/events. Otherwise, you might be able to find a few methods which will appear to trigger some of the media functions in WebGL - as there are a few methods which do work in WebGL - depending on many factors such as the architecture of your scene and the loading and handling of scene assets (media). However, you will spend countless hours discovering and testing, only to find such methods do not work consitantly in every OS, device, browser, etc., as this is a common waste of time which even developers highly experienced in WebGL often find themselves.

So until there are new and reliable APIs specifically developed to handle media such as Web Audio API, and/or other methods or standards widely adopted to handle media in WebGL; the only way to create scenes which make use of external media - mainly audio and video - to work on most any device and OS, is to rely on HTML DOM nodes. So you must first load your media into memory (it is essential to embed the media into an HTML document), then buffer the media in the browser (also essential, as loading does not buffer) by using either autoplay when this is natively enabled in the OS, or by providing the user with a control to initialize play() on any OS which doesn't enable autoplay natively; and then call each DOM attribute/property for control or coordination of your media. Otherwise, you'll find the problems with media control and manipulation in WebGL to be a deep hole of anxiety which might sometimes appear to work, but has a zero chance of working across multiple OS, devices, and browsers - or with any reliability at all if you do find a method which "appears" to work on one or more of your devices.

I hope that no other developers waste the countless hours which I and many others have spent trying to solve the conflicts we've discovered in using media in WebGL, and expecting a rational and reasonable result; since most of the functionality you might expect from your experience in using HTML media, as well as other media such as the use of images as textures in WebGL - simply does not function as you might have expected. And the only reliable process (and I mean  "the only" one) to gain full control over your media in any OS using WebGL is to use HTML media and the massive number of events which are standard in every browser. It takes a small amount of testing to fully understand how media performs in WebGL as well as on each OS, device, etc., but is the only way to assure compatability and functionality for most all platforms and devices. I've spent more time working on developing "useless" methods to maniulate media in WebGL than any other aspect of WebGL development, and hope that this info is carried through the forum - especially to any newbies, as I have probably tried to answer more posts about issues with media in WebGL than any other problem - and the answer is almost always due to how WebGL handles (or doesn't handle) media uniquely for each OS, browser, and often a specific device.

Cheers,

DB

Link to comment
Share on other sites

  • 7 months later...

Sorry to dig up an old issue but I have a problem getting a .wav or .mp3 to play upon scene load. I put the file in the same folder as my JS file and call 

 

var music = new BABYLON.Sound("Test", "test.wav", scene, function(){
        console.log('music called!')
      }, { loop: true, autoplay: true });
music.play();

 

However, I get the errors: 

 

Error while decoding audio data for: Test / Error: EncodingError: Unable to decode audio data

Uncaught (in promise) DOMException: Unable to decode audio data 

 

Any help would be appreciated!

 

 

Link to comment
Share on other sites

Are you sure that your browser supports wav? otherwise try mp3

Also check that the file or test.wav test.mp3 has the ebon way to indicate from running your html file.

var music = new BABYLON.Sound("Test", "root/test.wav", scene, function(){
        console.log('music called!')
      }, { loop: true, autoplay: true });

This is not necessary for you to use autoplay: true the options :

music.play();

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...