فهرست منبع

Merge pull request #6522 from nbduke/master

 Added ability to skip codec check on URLs when constructing a Sound
David Catuhe 6 سال پیش
والد
کامیت
cbfd840814
2فایلهای تغییر یافته به همراه12 افزوده شده و 12 حذف شده
  1. 3 0
      dist/preview release/what's new.md
  2. 9 12
      src/Audio/sound.ts

+ 3 - 0
dist/preview release/what's new.md

@@ -65,6 +65,9 @@
 - Added `ShaderMaterial.setColor4Array` ([JonathanTron](https://github.com/JonathanTron/))
 - Added `ShaderMaterial.setArray4` ([JonathanTron](https://github.com/JonathanTron/))
 
+### Sounds
+- Added `ISoundOptions.skipCodecCheck` to make `Sound` more flexible with URLs ([nbduke](https://github.com/nbduke))
+
 ### Documentation
 - Added a note on shallow bounding of getBoundingInfo ([tibotiber](https://github.com/tibotiber))
 

+ 9 - 12
src/Audio/sound.ts

@@ -68,6 +68,10 @@ export interface ISoundOptions {
      * Defines an optional offset (in seconds) inside the sound file
      */
     offset?: number;
+    /**
+     * If true, URLs will not be required to state the audio file codec to use.
+     */
+    skipCodecCheck?: boolean;
 }
 
 /**
@@ -278,18 +282,11 @@ export class Sound {
                             // If we found a supported format, we load it immediately and stop the loop
                             for (var i = 0; i < urls.length; i++) {
                                 var url = urls[i];
-                                if (url.indexOf(".mp3", url.length - 4) !== -1 && Engine.audioEngine.isMP3supported) {
-                                    codecSupportedFound = true;
-                                }
-                                if (url.indexOf(".ogg", url.length - 4) !== -1 && Engine.audioEngine.isOGGsupported) {
-                                    codecSupportedFound = true;
-                                }
-                                if (url.indexOf(".wav", url.length - 4) !== -1) {
-                                    codecSupportedFound = true;
-                                }
-                                if (url.indexOf("blob:") !== -1) {
-                                    codecSupportedFound = true;
-                                }
+                                codecSupportedFound = (options && options.skipCodecCheck) ||
+                                    (url.indexOf(".mp3", url.length - 4) !== -1 && Engine.audioEngine.isMP3supported) ||
+                                    (url.indexOf(".ogg", url.length - 4) !== -1 && Engine.audioEngine.isOGGsupported) ||
+                                    (url.indexOf(".wav", url.length - 4) !== -1) ||
+                                    (url.indexOf("blob:") !== -1);
                                 if (codecSupportedFound) {
                                     // Loading sound using XHR2
                                     if (!this._streaming) {