Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate AudioContext.decodeAudioData's error to AudioLoader.load #20301

Closed
wants to merge 1 commit into from

Conversation

yuntonyx
Copy link

@yuntonyx yuntonyx commented Sep 9, 2020

In some cases AudioContext.decodeAudioData can fail. For example, Safari doesn't support .ogg files, and decoding one triggers AudioContext.decodeAudioData's error handler. Instead of failing silently, it can be helpful to propagate this error to AudioLoader.load

reference: https://www.w3.org/TR/webaudio/#callback-decodeerrorcallback-parameters

@@ -33,6 +33,10 @@ AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {

onLoad( audioBuffer );

}, function ( error ) {

throw error;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using onError( e ); instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would skip the LoadingManager's error handler. Does it matter?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you throw an exception at this point, it is not handled by the catch block in line 42. Ideally, errors in the loading process always trigger the onError() callback so the user can decide how to proceed. The loading manager could be informed about the error like so:

if ( onError ) {

	onError( e );

} else {

	console.error( e );

}

scope.manager.itemError( url );

Copy link
Collaborator

@Mugen87 Mugen87 Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I'm not sure LoadingManager can process the call of itemError() correctly since it would be triggered during the audio decode. At that point, itemEnd() was already called by FileLoader.

The fact that AudioLoader does a decode can actually produce a race condition in context with LoadingManager: #10706 (not sure why the issue was closed since this bug still exists).

@Mugen87
Copy link
Collaborator

Mugen87 commented Sep 21, 2020

Closing. Let's reconsider the error handling when #10706 is fixed. For now, you have to check if browser support the respective formats before using AudioLoader.load().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants