question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MediaPlayer cant play the uri startswith `pack://...`

See original GitHub issue
  • .NET Core Version: 6.0.2
  • Windows version: win11
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Dont know
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)? NO
  • Security issues and bugs should be reported privately, learn more via our responsible disclosure guidelines.

Problem description:

MediaPlayer cant play the uri startswith pack://.... such as

// play failed
string uriString1 = $"pack://application:,,,/Lyre.Player.Plugin;component/Resources/FloralZither.mp3";
MediaPlayer player1 = new();
player1.Open(new Uri(uriString1));
player1.Play();

// play ok
string uriString2 = @$"D:\GitHub\Snap.Genshin\Plugins\SG.Plugin.Lyre.Player\src\Resources\FloralZither.mp3";
MediaPlayer player2 = new();
player2.Open(new Uri(uriString2));
player2.Play();

Actual behavior: UriSchemePack type uri cant be played using MediaPlayer.

Expected behavior:

Minimal repro:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ThomasGoulet73commented, Mar 1, 2022

You were faster than me 😄. Here’s the code that throws when using pack for reference: https://github.com/dotnet/wpf/blob/4af440108d50958a2ac3e3f67a454aa0cd142e5c/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaPlayerState.cs#L844-L855

Does MediaPlayer intend to append the API that passes the Stream parameter for opening file? This repo is probably not the right place to ask this question since Windows Media Player is probably maintained by the Windows team. I would recommend using third-party solutions which might support using a Stream (VLC based player might support it).

1reaction
emakocommented, Mar 1, 2022

Try VLC or extract the file from the assembly to fix problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How would I use a pack uri resource with media player?
I have a resource wav file at the root of my assembly called "notify.wav", but I have no way to pass it into...
Read more >
Uri | Android Developers
Returns true if this URI is relative, i.e. if it doesn't contain an ... Absolute URIs are hierarchical if the scheme-specific part starts...
Read more >
sdk/sources/android-25/android/media/MediaPlayer.java
error conditions, the internal player engine invokes a user supplied ... synchronously instantiating a MediaPlayer from a Uri or resource.
Read more >
media/java/android/media/MediaPlayer.java
error conditions, the internal player engine invokes a user supplied ... synchronously instantiating a MediaPlayer from a Uri or resource.
Read more >
Play audio and video with MediaPlayer - UWP applications
This article shows you how to play media in your Universal Windows app with MediaPlayer.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found