使用MediaElement在#path中播放来自网络驱动器的文件

时间:2016-09-20 12:31:14

标签: c# wpf uri mediaelement

Repro代码:

<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>
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");
    }
}

如果我尝试在网络驱动器的路径中打开一个#的文件,则会失败并显示:

  

HRESULT的异常:0xC00D11B1

如果我从路径

中删除#,剪辑可以正常播放

我做错了什么?

更新: Windows媒体播放器使用路径中的#从网络驱动器播放剪辑。

1 个答案:

答案 0 :(得分:1)