为什么wmp.currentMedia.duration.ToString();显示0呀啊?
WMPLib.WindowsMediaPlayerwmp=newWindowsMediaPlayer();privatevoidbutton2_Click(objects...
WMPLib.WindowsMediaPlayer wmp = new WindowsMediaPlayer();
private void button2_Click(object sender, EventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
this.Text = "[" + this.textBox1.Text.Substring(this.textBox1.Text.LastIndexOf("\\") + 1) + "]--精品音乐";
wmp.URL = this.textBox1.Text;//this.textBox1.Text是媒体文件的路径和名字
this.label2.Text = wmp.currentMedia.duration.ToString();
wmp.settings.setMode("loop", true);
wmp.controls.play();
}
else
{
this.button1.PerformClick();
}
} 展开
private void button2_Click(object sender, EventArgs e)
{
if (this.listBox1.SelectedItem != null)
{
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
this.Text = "[" + this.textBox1.Text.Substring(this.textBox1.Text.LastIndexOf("\\") + 1) + "]--精品音乐";
wmp.URL = this.textBox1.Text;//this.textBox1.Text是媒体文件的路径和名字
this.label2.Text = wmp.currentMedia.duration.ToString();
wmp.settings.setMode("loop", true);
wmp.controls.play();
}
else
{
this.button1.PerformClick();
}
} 展开
1个回答
2013-12-27
展开全部
要play()了之后才能显示durationString,你加个play的状态检测的代码就行了:
using System;
class Test
{
static WMPLib.WindowsMediaPlayer wmp;
static void Main()
{
wmp = new WMPLib.WindowsMediaPlayer();
wmp.URL = @"C:\thoulan.mp3";
wmp.controls.play();
wmp.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(wmp_PlayStateChange);
Console.Read();
}
static void wmp_PlayStateChange(int state)
{
if (state == 3) Console.WriteLine(wmp.currentMedia.durationString);
}
}
状态码: http://msdn.microsoft.com/en-us/library/ms533677%28VS.85%29.aspx
using System;
class Test
{
static WMPLib.WindowsMediaPlayer wmp;
static void Main()
{
wmp = new WMPLib.WindowsMediaPlayer();
wmp.URL = @"C:\thoulan.mp3";
wmp.controls.play();
wmp.PlayStateChange +=
new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(wmp_PlayStateChange);
Console.Read();
}
static void wmp_PlayStateChange(int state)
{
if (state == 3) Console.WriteLine(wmp.currentMedia.durationString);
}
}
状态码: http://msdn.microsoft.com/en-us/library/ms533677%28VS.85%29.aspx
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询