From b93f373d0a8b1b831f194f6eb59ee276c579d723 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 30 Oct 2017 16:28:43 -0700 Subject: [PATCH] Minor changes --- lime/media/AudioBuffer.hx | 69 +++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/lime/media/AudioBuffer.hx b/lime/media/AudioBuffer.hx index c3a292d2c3..7b5c779bf5 100644 --- a/lime/media/AudioBuffer.hx +++ b/lime/media/AudioBuffer.hx @@ -1,9 +1,9 @@ package lime.media; +import haxe.crypto.Base64; import haxe.io.Bytes; import haxe.io.Path; -import haxe.crypto.Base64; import lime._backend.native.NativeCFFI; import lime.app.Future; import lime.app.Promise; @@ -11,8 +11,8 @@ import lime.media.codecs.vorbis.VorbisFile; import lime.media.openal.AL; import lime.media.openal.ALBuffer; import lime.net.HTTPRequest; -import lime.utils.UInt8Array; import lime.utils.Log; +import lime.utils.UInt8Array; #if howlerjs import lime.media.howlerjs.Howl; @@ -55,8 +55,9 @@ class AudioBuffer { public function new () { - - + + + } @@ -88,39 +89,21 @@ class AudioBuffer { #end - #if (js && html5 && howlerjs) - private static function __getCodec (bytes:Bytes):String { - - var signature = bytes.getString(0, 4); - switch (signature) { - case "OggS": return "audio/ogg"; - case "fLaC": return "audio/flac"; - case "RIFF" if (bytes.getString(8, 4) == "WAVE"): return "audio/wav"; - default: if (bytes.getString(0, 3) == "ID3" || bytes.getString(0, 2) == "ÿû") { - - return "audio/mp3"; - - } - } - - Log.error("Unsupported sound format"); - return null; - } - #end - - public static function fromBase64 (base64String:String):AudioBuffer { if (base64String == null) return null; #if (js && html5 && howlerjs) + // if base64String doesn't contain codec data, add it. if (base64String.indexOf(",") == -1) { + base64String = "data:" + __getCodec (Base64.decode (base64String)) + ";base64," + base64String; + } var audioBuffer = new AudioBuffer (); - audioBuffer.src = new Howl ({ src: [base64String], html5: true, preload: false }); + audioBuffer.src = new Howl ({ src: [ base64String ], html5: true, preload: false }); return audioBuffer; #elseif lime_console @@ -169,10 +152,11 @@ class AudioBuffer { public static function fromBytes (bytes:Bytes):AudioBuffer { if (bytes == null) return null; + #if (js && html5 && howlerjs) var audioBuffer = new AudioBuffer (); - audioBuffer.src = new Howl ({ src: ["data:" + __getCodec (bytes) + ";base64," + Base64.encode (bytes)], html5: true, preload: false }); + audioBuffer.src = new Howl ({ src: [ "data:" + __getCodec (bytes) + ";base64," + Base64.encode (bytes) ], html5: true, preload: false }); return audioBuffer; @@ -474,9 +458,38 @@ class AudioBuffer { } + private static function __getCodec (bytes:Bytes):String { + + var signature = bytes.getString (0, 4); + + switch (signature) { + + case "OggS": return "audio/ogg"; + case "fLaC": return "audio/flac"; + case "RIFF" if (bytes.getString (8, 4) == "WAVE"): return "audio/wav"; + default: + + if (bytes.getString (0, 3) == "ID3" || bytes.getString (0, 2) == "ÿû") { + + return "audio/mp3"; + + } + + } + + Log.error ("Unsupported sound format"); + return null; + + } + + + + // Get & Set Methods + + private function get_src ():Dynamic { #if (js && html5) @@ -543,4 +556,4 @@ class AudioBuffer { } -} +} \ No newline at end of file