diff --git a/modules/mojo/native/asyncsoundloader.js b/modules/mojo/native/asyncsoundloader.js index 292dbe5e..8cde3282 100644 --- a/modules/mojo/native/asyncsoundloader.js +++ b/modules/mojo/native/asyncsoundloader.js @@ -1,11 +1,39 @@ function BBAsyncSoundLoaderThread(){ + this._running=false; } BBAsyncSoundLoaderThread.prototype.Start=function(){ - this._sample=this._device.LoadSample( this._path ); + this._sample = null; + if( !this._device.okay ) return; + + var audio=new Audio(); + if( !audio ) return; + + var thread=this; + thread._running=true; + + audio.src=BBGame.Game().PathToUrl( this._path ); + audio.preload='auto'; + + var success=function( e ){ + thread._running=false; + thread._sample = new gxtkSample( audio ); + audio.removeEventListener( 'canplaythrough',success,false ); + audio.removeEventListener( 'error',error,false ); + } + + var error=function( e ){ + thread._running=false; + audio.removeEventListener( 'canplaythrough',success,false ); + audio.removeEventListener( 'error',error,false ); + } + + audio.addEventListener( 'canplaythrough',success,false ); + audio.addEventListener( 'error',error,false ); + audio.load(); } BBAsyncSoundLoaderThread.prototype.IsRunning=function(){ - return false; + return this._running; } diff --git a/modules/mojo/native/mojo.html5.js b/modules/mojo/native/mojo.html5.js index fdabab17..c141deea 100644 --- a/modules/mojo/native/mojo.html5.js +++ b/modules/mojo/native/mojo.html5.js @@ -426,6 +426,9 @@ gxtkAudio.prototype.Resume=function(){ gxtkAudio.prototype.LoadSample=function( path ){ if( !this.okay ) return null; + + var ty=this.game.GetMetaData( path,"type" ); + if(ty != "" && ty.indexOf( "audio/" ) != 0 ) return null; var audio=new Audio( this.game.PathToUrl( path ) ); if( !audio ) return null; @@ -524,9 +527,10 @@ gxtkAudio.prototype.PlayMusic=function( path,flags ){ this.StopMusic(); this.music=this.LoadSample( path ); - if( !this.music ) return; + if( !this.music ) return -1; this.PlaySample( this.music,32,flags ); + return 0; } gxtkAudio.prototype.StopMusic=function(){ diff --git a/src/transcc/builders/html5.monkey b/src/transcc/builders/html5.monkey index 725b907a..3bffd7cc 100644 --- a/src/transcc/builders/html5.monkey +++ b/src/transcc/builders/html5.monkey @@ -119,6 +119,12 @@ Class Html5Builder Extends Builder meta.Push "width="+Info_Width+";" meta.Push "height="+Info_Height+";" meta.Push "\n" + Case "wav","ogg","mp3","m4a" + If ext="mp3" ext="mpeg" + If ext="m4a" ext="x-m4a" + + meta.Push "[" + kv.Value + "];type=audio/" + ext + ";" + meta.Push "\n" End Next Return meta.Join("")