Jump to content

Audio streaming


KarelAnker
 Share

Recommended Posts

Is this possible with Babylon, as creating a new BABYLON.Sound will preload your song fully before you can listen to it. I basically want it to download parts. When you have a 10 minute song, I don't want it to download all the 10 minutes, I want it to download the part it's currently playing + some minutes.

Link to comment
Share on other sites

I've just finished my tests and published the updated version of BABYLON.Sound on the github: https://github.com/BabylonJS/Babylon.js/blob/master/src/Audio/babylon.sound.ts

 

It will be on the playground soon and I'll share a demo on it.

 

In the meantime, it's very easy to use. Just set a 'streaming: true' in the options of the Sound constructor and it will stream the sound using the HTML Audio tag rather than downloading & decoding it first.

 

Ex: var violons18 = new BABYLON.Sound("Violons", "./coding4fun2015.mp3", scene, null, { loop: true, autoplay: true, streaming: true });

 

All other features are implemented to support this new source: pause, stop, play, 3D spatialization, analyser & directional sound.

Link to comment
Share on other sites

EDIT:

It seems that the HTML5 audio tag does not allow any streaming outside of the local file system.

 

Try streaming "http://ccmixter.org/content/teru/teru_-_We_re_on_the_Roll.mp3", the header has Access-Control-Allow-Origin: *, but for some reason when you're trying to stream Chrome outputs "MediaElementAudioSource outputs zeroes due to CORS access restrictions for ......."

 

You can check the receiving headers at http://www.rexswain.com/httpview.html

Link to comment
Share on other sites

Got it to work! You basically forgot to set the crossOrigin attribute to anonymous.

var music = new BABYLON.Sound("Music", ........................);music._htmlAudioElement.crossOrigin = "anonymous";

I would create a pull request but I don't dare to touch it  ;)

 

(Also, it seems that you can't attach the audio to an object, it's always 2D with the streaming tag)

Link to comment
Share on other sites

Got it to work! You basically forgot to set the crossOrigin attribute to anonymous.

var music = new BABYLON.Sound("Music", ........................);music._htmlAudioElement.crossOrigin = "anonymous";

I would create a pull request but I don't dare to touch it  ;)

 

(Also, it seems that you can't attach the audio to an object, it's always 2D with the streaming tag)

 

You can make it a 3D sound. Simply attach the sound to a mesh or use the boolean to make it 3D.

 

David

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...