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:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 aStream
(VLC based player might support it).Try VLC or extract the file from the assembly to fix problem.