问题描述
在Windows Forms 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;
}
}
}
解决方法
感谢@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;
}