unoplatform/uno · error · NotSupportedException

IMediaSource is not supported

Error message

IMediaSource is not supported

What it means

NotSupportedException thrown by MediaPlayerExtension.SetMediaSource on WebAssembly. The WASM media extension does not implement IMediaSource-based playback (only Uri sources are supported via SetUriSource). Any call to SetMediaSource throws unconditionally.

Source

Thrown at src/AddIns/Uno.UI.MediaPlayer.WebAssembly/MediaPlayerExtension.cs:467

					this.Log().Debug($"MediaPlayerExtension.Play(): Player was not prepared");
				}
			}
		}
		catch (global::System.Exception ex)
		{
			if (this.Log().IsEnabled(LogLevel.Debug))
			{
				this.Log().Debug($"MediaPlayerExtension.Play(): Failed {ex}");
			}
			OnMediaFailed(ex);
		}
	}

	public void SetFileSource(IStorageFile file)
		=> throw new NotSupportedException($"IStorageFile is not supported");

	public void SetMediaSource(IMediaSource source)
		=> throw new NotSupportedException($"IMediaSource is not supported");

	public void SetStreamSource(IRandomAccessStream stream)
		=> throw new NotSupportedException($"IRandomAccessStream is not supported");

	public void SetSurfaceSize(Size size)
		=> throw new NotSupportedException($"SetSurfaceSize is not supported");

	public void SetUriSource(Uri uri)
	{
		if (this.Log().IsEnabled(LogLevel.Debug))
		{
			this.Log().Debug($"MediaPlayerExtension.SetUriSource({uri})");
		}

		if (_player is not null)
		{
			_player.Source = uri.OriginalString;
		}

View on GitHub (pinned to 0418340488)

Solutions

  1. On WASM, resolve a Uri from your source and call SetUriSource instead.
  2. Branch source-setting by platform to avoid SetMediaSource on WASM.
  3. Guard the call site with a platform/runtime check (OperatingSystem.IsBrowser()).
  4. Upgrade the add-in; if IMediaSource support is added later, match versions.

Example fix

// before — shared call
extension.SetMediaSource(mediaSource);

// after — use Uri on WASM
#if __WASM__
    extension.SetUriSource(mediaSource.Uri);
#else
    extension.SetMediaSource(mediaSource);
#endif
Defensive patterns

Strategy: validation

Validate before calling

// Do not call SetMediaSource on WASM
if (!OperatingSystem.IsBrowser())
    extension.SetMediaSource(source);
else
    throw new PlatformNotSupportedException("Use SetUriSource on WASM");

Type guard

bool SupportsMediaSource() => !OperatingSystem.IsBrowser();

Try / catch

try { extension.SetMediaSource(source); }
catch (NotSupportedException ex) when (ex.Message.Contains("IMediaSource"))
{ Log.Error("IMediaSource unsupported on WASM — resolve a Uri"); }

Prevention

When it happens

Trigger: Calling SetMediaSource(IMediaSource) on the WASM media extension — e.g. shared code that builds an IMediaSource and passes it cross-platform.

Common situations: Cross-platform media initialization that uses IMediaSource abstractions; porting desktop behavior where IMediaSource is supported to WASM.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/0c3f330e27cca4ce. Report an issue: GitHub.