Jump to content

Get music to play at or before scene rendering starts


andrew_
 Share

Recommended Posts

I'm doing this: 

var assets = [];var loader = new BABYLON.AssetsManager(scene);var toLoad = [	{ltype: "m", name : "lilly", src : "assets/507601_Lilly.mp3" }					];        toLoad.forEach(function(obj) {		                if (obj.ltype=="m")		{		var binaryTask = loader.addBinaryFileTask(obj.name, obj.src);		binaryTask.onSuccess = function (task) {		music = new BABYLON.Sound("lilly", task.data, scene, 		function () {		// Sound has been downloaded & decoded		music.setVolume(0.1);		music.play();		}, { loop: true });	}}

and then this:

loader.onFinish = function() {		// call the createScene function		createScene();										// run the render loop		engine.runRenderLoop(function(){				scene.render();		});}loader.load();

This works fine in that the music plays, but it doesn't start until the scene has been rendered for about 2 seconds.

I was trying to get the music to start first, or at the same time as the scene animation starts.

 

Thanks for help!

 

 

Link to comment
Share on other sites

One thing I found out looking at when a sound is specified in FileLoader.ts is it puts a block in until the sound is ready to play.  Something like this:

var sound;sound = new BABYLON.Sound("sceneSound.wav", soundsRootDir + "sceneSound.wav", scene,                           () => { scene._removePendingData(sound); },                           {autoplay: true, loop: false});scene._addPendingData(sound);

Maybe this will delay rendering till sound is ready, then block removed in success callback.  Wonder what happens should url be wrong though.  When implementing this using asset manager, the block and release might go in different spots.  I know very little about AssetsManager.

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