Skip to content

Add onMediaError instance method - #1379

Open
captbaritone wants to merge 2 commits into
masterfrom
on-media-error
Open

captbaritone wants to merge 2 commits into
masterfrom
on-media-error

Conversation

@captbaritone

Copy link
Copy Markdown
Owner

When a track can't be fetched or decoded, ElementSource logs the error, then triggers ended and sets the status to STOPPED. That keeps Webamp from getting stuck, but it means an embedder can't tell an undecodable file from the end of a track. agentcloud currently works around this by probing the same URL with a hidden <audio> element.

This adds a public signal:

const unsubscribe = webamp.onMediaError(({ code }) => {
  if (code === MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED) {
    showUnsupportedFileMessage();
  }
});

code is the underlying MediaError.code. It's passed in an object so more fields can be added later without breaking callers.

Implementation

  • ElementSource emits "error" with the code, just before its existing "ended".
  • Media re-emits it, and the media middleware dispatches a new MEDIA_ERROR action.
  • onMediaError subscribes to that action, the same way onClose/onMinimize do.
  • Behavior is otherwise unchanged. The error is still logged, and Webamp still continues as if the track ended. Embedders get onMediaError before the resulting track change.

Documented in the instance methods docs.

Testing

  • New onMediaError.test.ts constructs a real WebampLazy with a fake media class via the existing __customMediaClass option, emits "error", and checks that the callback gets { code } and that unsubscribing works.
  • tsc, eslint, prettier --check and vitest run pass locally.

When a track fails to load or decode, Webamp logs the error and continues as
if the track had ended, so embedders could not tell an unplayable file from
the end of a track.

ElementSource now emits an "error" event with the MediaError code, which
Media re-emits and the media middleware dispatches as MEDIA_ERROR. The new
webamp.onMediaError(cb) subscribes to it. The existing behavior of treating
the error as the end of the track is unchanged.
@netlify

netlify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tourmaline-kringle-c98715 ready!

Name Link
🔨 Latest commit df1a5e5
🔍 Latest deploy log https://app.netlify.com/projects/tourmaline-kringle-c98715/deploys/6acd35ce9de1902209c4996d
😎 Deploy Preview https://deploy-preview-1379--tourmaline-kringle-c98715.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

Copy link
Copy Markdown

Size Change: +132 B (+0.03%)

Total Size: 490 kB

📦 View Changed
Filename Size Change
packages/webamp/built/webamp.bundle.min.js 298 kB +71 B (+0.02%)
packages/webamp/built/webamp.lazy-bundle.min.js 192 kB +61 B (+0.03%)

compressed-size-action

This branch has not been deployed

No deployments
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.

1 participant