From 89e51ca09672d7161ada3e9a9bd9707a2821fe20 Mon Sep 17 00:00:00 2001 From: Jacob Stephens Date: Sun, 31 May 2026 10:18:42 -0400 Subject: [PATCH] windows: fix silent audio in unpackaged build (ms-appx -> file path) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The app ships unpackaged (WindowsPackageType=None), so the ms-appx:///Assets/waterfall.mp3 URI has no package identity to resolve against and MediaPlayer silently fails to open the asset — the window shows but no sound plays. Load the asset by its real path next to the executable via AppContext.BaseDirectory, which resolves correctly in both packaged and unpackaged builds. Also add a MediaFailed handler so future open failures surface in Debug output instead of failing silently. Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/windows/Cascade/Services/AudioEngine.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/apps/windows/Cascade/Services/AudioEngine.cs b/apps/windows/Cascade/Services/AudioEngine.cs index cc49a70..0b430a6 100644 --- a/apps/windows/Cascade/Services/AudioEngine.cs +++ b/apps/windows/Cascade/Services/AudioEngine.cs @@ -1,4 +1,6 @@ using System; +using System.Diagnostics; +using System.IO; using Windows.Media.Core; using Windows.Media.Playback; @@ -27,11 +29,15 @@ public void EnsureLoaded() { if (_loaded) return; - // ms-appx scheme resolves to the app package's install directory in - // packaged builds; in unpackaged builds, MediaSource.CreateFromUri - // also accepts ms-appx as long as the file is alongside the .exe. - var uri = new Uri("ms-appx:///Assets/waterfall.mp3"); - var item = new MediaPlaybackItem(MediaSource.CreateFromUri(uri)); + // This app ships unpackaged (WindowsPackageType=None), so the + // ms-appx:/// scheme has no package identity to resolve against and + // MediaPlayer silently fails to open the asset. Load it by its real + // path next to the executable instead. AppContext.BaseDirectory is the + // install directory in both packaged and unpackaged builds, so this + // works everywhere. + var assetPath = Path.Combine(AppContext.BaseDirectory, "Assets", "waterfall.mp3"); + _player.MediaFailed += OnMediaFailed; + var item = new MediaPlaybackItem(MediaSource.CreateFromUri(new Uri(assetPath))); _list = new MediaPlaybackList { AutoRepeatEnabled = true }; _list.Items.Add(item); _player.Source = _list; @@ -40,6 +46,9 @@ public void EnsureLoaded() _loaded = true; } + private static void OnMediaFailed(MediaPlayer sender, MediaPlayerFailedEventArgs args) => + Debug.WriteLine($"[Cascade] MediaFailed: {args.Error} - {args.ErrorMessage}"); + public void Start(int volumePercent) { EnsureLoaded();