AxWMPLib.AxWindowsMediaPlayer has presented weird behavior for WMV files

340 views Asked by At

In my Windows Forms C# application I implemented the COM AxWMPLib.AxWindowsMediaPlayer, I have a button which sets the currentPosition, however it has shown a weird behavior when it comes to WMV files, it does NOT set the currentPosition properly, instead it gets a 2~6 seconds difference.

In the following example I set currentPosition to 7 but it actually sets back to 5 or sometimes 4, why? It only happens on WMV files though, MKV and MP4 are working fine.

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

Is that a bug? How to fix it? Is there a workaround for WMV files?

1

There are 1 answers

0
Simple On BEST ANSWER

Thanks for @Hans Passant comment. According to this answer: https://superuser.com/questions/591904/windows-media-player-v12-seek-position-wont-play-from-a-chosen-position

It seems WMV has encoding issues. Besides MKV and MP4 file formats are working fine I did lots of tests in order to find similar issues on other file formats such as: AVI, WebM, 3GP, MPG, VOB, MOV, FLV.

WMV is the only one which presented issues. So I made this workaround for WMV files:

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