使用MediaElement从网络驱动器播放包含“#”路径的文件

3

代码示例:

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

如果我从网络驱动器上打开路径中包含 # 的文件,则会失败,出现以下错误消息:

Exception from HRESULT: 0xC00D11B1

如果从路径中删除 #,则片段可以正常播放。
那么我错在哪里了呢?
更新: Windows 媒体播放器可以从路径中包含 # 的网络驱动器播放该片段。

它运行得非常好。 - jsanalytics
@jstreet 奇怪,这段代码对我来说是完美的可复现的。 - Johan Larsson
我会尝试获取完整的异常堆栈跟踪。 - jsanalytics
1个回答

1

如果我从路径中删除 #,剪辑就可以正常播放,所以这不应该是编解码器问题。 - Johan Larsson
请您在上面给出的链接中查看“Eddie Li - MSFT的答案”,也许会有所帮助。 - FreeMan
源URI中的错误链接对你有效吗? - Johan Larsson
实际上,你的代码对我来说不需要做任何事情就可以工作。我只是复制和粘贴了它。它能够工作。但只要我在论坛中搜索你写的错误代码,Eddie Li - MSFT在上面链接中的回答就有意义。我在不同的论坛上看到了类似的错误代码答案。 - FreeMan
只是确认一下:这段代码适用于带有路径中 # 的映射驱动器上的文件吗?对我来说,当在本地磁盘上时,它可以处理路径中带有 #。在没有 # 的网络驱动器上也可以正常播放。 - Johan Larsson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接