dotnet / dotnet/wpf

WPF MediaElement Source fails to load because of percent encoding

Open
#9,296 7 comments 0 reactions 0 assignees View on GitHub
:mailbox_with_no_mail: waiting-author-feedback
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/WPF-MediaElement-Source-fails-to-load-be/10641667)._

---
[severity:Other]
Consider the following snippet;
var file1 = @"\\192.168.0.1\videos\alarm 10 %.mp4";
var file2 = @"\\192.168.0.1\videos\alarm 10 pct.mp4";
MediaElement.Source = new Uri(file1); // fails
MediaElement.Source = new Uri(file2); // works

With VS22 & .NET 4.8, file1 fails because the URI does not (cannot) escape the string properly. ie: the MediaElement reports the error as a file not found exception. Both, file1 and file2, naming patterns work if the files are located on a mapped drive. Having said that, this leads me to believe that this must be a bug since Windows media player does not share this problem. My understanding is that the MediaElement is a derivative control of the windows media player ... or vice versa.

Nothing i can do to the string has worked. i cannot even disable the percent encoding and perform the escaping myself. Furthermore, downloading the file before playing is not practical for many reasons. Nor is;
* renaming the file remotely.
* asking end users to rename all offending their files.
* mapping network drives before use wrt their hives.

In the end, I wouldn't even know how to logically explain this issue at all.

Thank you
[Redacted]@[Redacted]

PS: do not hesitate to contact me if greater detail is required.

---
### Original Comments

#### Feedback Bot on 4/19/2024, 11:04 AM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.