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();
}
}
为什么wmp.currentMedia.duration.ToString();显示0呀啊?
答案:1 悬赏:20 手机版
解决时间 2021-06-03 18:00
- 提问者网友:星軌
- 2021-06-03 09:09
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-06-03 10:23
要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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯