C# 使用MediaElement在路径中使用#从网络驱动器播放文件

C# 使用MediaElement在路径中使用#从网络驱动器播放文件,c#,wpf,uri,mediaelement,C#,Wpf,Uri,Mediaelement,复制代码: <Window x:Class="MediaBox.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MediaBox" Title="MainWi

复制代码:

<Window x:Class="MediaBox.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:MediaBox"
        Title="MainWindow">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <MediaElement LoadedBehavior="Play"
                      MediaFailed="OnMediaFailed"
                      Source="{Binding RelativeSource={RelativeSource FindAncestor,
                                                                      AncestorType={x:Type local:MainWindow}},
                                       Path=FileName}" />
        <Button Grid.Row="1"
                Click="OnOpenClick"
                Content="Open" />
    </Grid>
</Window>
如果我试图打开网络驱动器路径中带有
#
的文件,则会失败:

来自HRESULT的异常:0xC00D11B1

如果我将#从路径中移除,则片段播放效果良好

我做错了什么

更新:
Windows media player播放路径中带有#的网络驱动器中的剪辑。

对我来说效果很好。但据我从错误代码中了解,这似乎是一个编解码器问题。请看一看

效果很好。@jstreet奇怪,这段代码对我来说是一个完美的复制。我会尝试获取完整的异常堆栈跟踪。如果我从路径中删除#,这应该不是一个编解码器问题,因为剪辑播放效果很好。你能检查上面给定链接中的“Eddie Li-MSFT的答案”吗?也许它有帮助。关于源URI中错误的链接对你有用吗?实际上,你的代码对我有效,什么都不做。我只是复制和粘贴。它有效。但只要我搜索你在论坛上写的错误代码,Eddie Li-MSFT在上面链接中的答案就有意义。我在不同论坛上看到了错误代码的答案。我只是想确认一下:该代码是否适用于路径中有#的映射驱动器上的文件?对于med,它在本地磁盘上与路径中的#一起工作。在没有#的网络驱动器上可以正常播放。
public partial class MainWindow : Window
{
    public static readonly DependencyProperty FileNameProperty = DependencyProperty.Register(
        nameof(FileName),
        typeof(string),
        typeof(MainWindow),
        new PropertyMetadata(default(string)));

    public MainWindow()
    {
        this.InitializeComponent();
    }

    public string FileName
    {
        get { return (string)this.GetValue(FileNameProperty); }
        set { this.SetValue(FileNameProperty, value); }
    }

    private void OnOpenClick(object sender, RoutedEventArgs e)
    {
        var openFileDialog = new OpenFileDialog();
        if (openFileDialog.ShowDialog() == true)
        {
            this.FileName = openFileDialog.FileName;
        }
    }

    private void OnMediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        MessageBox.Show(this, e.ErrorException.Message, "Media failed");
    }
}