【问题标题】:Play file from network drive with # in path using MediaElement使用 MediaElement 从带有 # 路径的网络驱动器播放文件
【发布时间】:2016-09-20 12:31:13
【问题描述】:

复制代码:

<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 媒体播放器播放来自网络驱动器的剪辑,路径中带有 #。

【问题讨论】:

  • 效果很好。
  • @jstreet 奇怪,代码对我来说是完美的复制品。
  • 我会尝试获取完整的异常堆栈跟踪。

标签: c# wpf uri mediaelement


【解决方案1】:

【讨论】:

  • 不应该是编解码器问题,因为如果我从路径中删除 #,剪辑可以正常播放。
  • 您能否在上面给定的链接中查看“Eddie Li - MSFT 的答案”?也许有帮助。
  • 源 URI 中有关错误的链接对您有用吗?
  • 实际上,您的代码无需任何操作即可为我工作。我只是复制和粘贴。它可以工作。但是只要我搜索你在论坛上写的错误代码,Eddie Li - MSFT在上面链接中的答案是有道理的。我在不同的论坛上看到了错误代码的这样的答案。
  • 只是为了确认:代码是否适用于路径中带有 # 的映射驱动器上的文件?对于 med,它在本地磁盘上与路径中的 # 一起使用。在没有#的网络驱动器上播放正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-11
  • 1970-01-01
  • 2013-08-17
  • 2010-12-12
  • 2017-05-11
相关资源
最近更新 更多