【问题标题】:AxWMPLib.AxWindowsMediaPlayer has presented weird behavior for WMV filesAxWMPLib.AxWindowsMediaPlayer 对 WMV 文件表现出奇怪的行为
【发布时间】:2020-10-14 14:02:00
【问题描述】:

在我的 Windows 窗体 C# 应用程序中,我实现了 COM AxWMPLib.AxWindowsMediaPlayer,我有一个设置 currentPosition 的按钮,但是它在涉及 WMV 文件时表现出奇怪的行为,它没有设置 currentPosition正确的是,它会得到 2~6 秒的差异。

在以下示例中,我将 currentPosition 设置为 7,但它实际上设置为 5 或有时为 4,为什么?它只发生在 WMV 文件上,但 MKV 和 MP4 工作正常。

namespace MediaPlayerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.URL = @"D:\Downloads\sample.wmv";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 7.0;
        }
    }
}

这是一个错误吗?如何解决?是否有针对 WMV 文件的解决方法?

【问题讨论】:

标签: c# .net windows-media-player wmp axwindowsmediaplayer


【解决方案1】:

感谢@Hans Passant 的评论。 根据这个答案:https://superuser.com/questions/591904/windows-media-player-v12-seek-position-wont-play-from-a-chosen-position

WMV 似乎存在编码问题。除了 MKV 和 MP4 文件格式运行良好之外,我进行了大量测试,以便在其他文件格式上找到类似的问题,例如:AVI、WebM、3GP、MPG、VOB、MOV、FLV。

WMV 是唯一存在问题的。 所以我为 WMV 文件做了这个解决方法:

private void button1_Click(object sender, EventArgs e)
{
    string isWMV = axWindowsMediaPlayer1.currentMedia.sourceURL;

    if (isWMV.EndsWith(".wmv"))
    {
        ToolTip toolTip = new ToolTip();
        toolTip.Show("It's disabled for WMV files due to the faulty WMV indexing table.", button1);
        return;
    }
    
    axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 7.0;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-05
    • 1970-01-01
    • 2020-03-08
    • 1970-01-01
    相关资源
    最近更新 更多