Browse Source

AudioLoader: Trigger the error callback when decodeAudioData fails (#25784)

* AudioLoader: Trigger the error callback when decodeAudioData fails

Currently, if the call to `context.decodeAudioData` fails for whatever reason, `AudioLoader.load` (and `loadAsync` by extension) will hang forever because there is no error handling for it. This PR adds the extra error handling for that scenario.

* fix lint errors
Luis Fonsi VEVO 2 years ago
parent
commit
f342395bfb
1 changed files with 14 additions and 8 deletions
  1. 14 8
      src/loaders/AudioLoader.js

+ 14 - 8
src/loaders/AudioLoader.js

@@ -32,25 +32,31 @@ class AudioLoader extends Loader {
 
 					onLoad( audioBuffer );
 
-				} );
+				}, handleError );
 
 			} catch ( e ) {
 
-				if ( onError ) {
+				handleError( e );
 
-					onError( e );
+			}
+
+		}, onProgress, onError );
 
-				} else {
+		function handleError( e ) {
 
-					console.error( e );
+			if ( onError ) {
 
-				}
+				onError( e );
 
-				scope.manager.itemError( url );
+			} else {
+
+				console.error( e );
 
 			}
 
-		}, onProgress, onError );
+			scope.manager.itemError( url );
+
+		}
 
 	}