From cef0ae9d8b3a6de1b3d35b05399ea3f86776b105 Mon Sep 17 00:00:00 2001 From: Arthur Bikmullin Date: Sat, 18 Jan 2014 22:06:30 +0400 Subject: [PATCH 1/5] Added generation of metadata for sound files --- src/transcc/builders/html5.monkey | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/transcc/builders/html5.monkey b/src/transcc/builders/html5.monkey index 725b907a..ded26735 100644 --- a/src/transcc/builders/html5.monkey +++ b/src/transcc/builders/html5.monkey @@ -119,6 +119,9 @@ Class Html5Builder Extends Builder meta.Push "width="+Info_Width+";" meta.Push "height="+Info_Height+";" meta.Push "\n" + Case "wav", "ogg", "mp3", "m4a" + meta.Push "[" + kv.Value + "];type=sound/" + ext + ";" + meta.Push "\n" End Next Return meta.Join("") From 9e2a1cf15200c1d84108f9b0bbb15b3d70f19fc1 Mon Sep 17 00:00:00 2001 From: Arthur Bikmullin Date: Sat, 18 Jan 2014 22:07:32 +0400 Subject: [PATCH 2/5] Fixed returned values of LoadSample and PlayMusic functions --- modules/mojo/native/mojo.html5.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/mojo/native/mojo.html5.js b/modules/mojo/native/mojo.html5.js index fdabab17..9594a71e 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.indexOf( "sound/" )!=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(){ From c093b042606fdde9f00df4acb82872339ba0c373 Mon Sep 17 00:00:00 2001 From: Arthur Bikmullin Date: Sun, 19 Jan 2014 17:59:05 +0400 Subject: [PATCH 3/5] Fixed audio MIME types --- modules/mojo/native/mojo.html5.js | 2 +- src/transcc/builders/html5.monkey | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/mojo/native/mojo.html5.js b/modules/mojo/native/mojo.html5.js index 9594a71e..b2d6b844 100644 --- a/modules/mojo/native/mojo.html5.js +++ b/modules/mojo/native/mojo.html5.js @@ -428,7 +428,7 @@ gxtkAudio.prototype.LoadSample=function( path ){ if( !this.okay ) return null; var ty=this.game.GetMetaData( path,"type" ); - if( ty.indexOf( "sound/" )!=0 ) return null; + if( ty.indexOf( "audio/" )!=0 ) return null; var audio=new Audio( this.game.PathToUrl( path ) ); if( !audio ) return null; diff --git a/src/transcc/builders/html5.monkey b/src/transcc/builders/html5.monkey index ded26735..3bffd7cc 100644 --- a/src/transcc/builders/html5.monkey +++ b/src/transcc/builders/html5.monkey @@ -119,8 +119,11 @@ Class Html5Builder Extends Builder meta.Push "width="+Info_Width+";" meta.Push "height="+Info_Height+";" meta.Push "\n" - Case "wav", "ogg", "mp3", "m4a" - meta.Push "[" + kv.Value + "];type=sound/" + ext + ";" + 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 From 965d4fb6cc3716a29eb5bc998e733c3ecd547741 Mon Sep 17 00:00:00 2001 From: Arthur Bikmullin Date: Sun, 19 Jan 2014 18:04:07 +0400 Subject: [PATCH 4/5] Improved async sound loader --- modules/mojo/native/asyncsoundloader.js | 32 +++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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; } From 55504672092aaa891d665c287f12ee49044a5d87 Mon Sep 17 00:00:00 2001 From: Arthur Bikmullin Date: Mon, 10 Mar 2014 17:46:18 +0400 Subject: [PATCH 5/5] Fixed sample loading by absolute url --- modules/mojo/native/mojo.html5.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mojo/native/mojo.html5.js b/modules/mojo/native/mojo.html5.js index b2d6b844..c141deea 100644 --- a/modules/mojo/native/mojo.html5.js +++ b/modules/mojo/native/mojo.html5.js @@ -428,7 +428,7 @@ gxtkAudio.prototype.LoadSample=function( path ){ if( !this.okay ) return null; var ty=this.game.GetMetaData( path,"type" ); - if( ty.indexOf( "audio/" )!=0 ) return null; + if(ty != "" && ty.indexOf( "audio/" ) != 0 ) return null; var audio=new Audio( this.game.PathToUrl( path ) ); if( !audio ) return null;