Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions apps/windows/Cascade/Services/AudioEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using Windows.Media.Core;
using Windows.Media.Playback;

Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Loading