怎么写listbox双击播放音乐
求补上双击listbox 播放音乐的那段代码 也就是最后一段代码using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using
namespace YIMedia
{
public partial class Form1 : Form
{
private xqMedia.Audio ad = null;
public Form1()
{
InitializeComponent();
}
/// <summary>
/// 关闭播放器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (ad != null)
ad.CloseMedia();
}
/// <summary>
/// 载入播放器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
ad = new xqMedia.Audio();
string[] path= Directory.GetFiles(@"C:\Users\Administrator\Desktop\新建文件夹");
for (int i = 0; i < path.Length; i++)
{
string fileName = Path.GetFileName(path[i]);
listBox1.Items.Add(fileName);
}
updateToolBar();
updateSum();
}
/// <summary>
/// 更新播放器上面各个bt的状态
/// </summary>
private void updateToolBar()
{
trackBar2.Enabled = trackBar1.Enabled = true;
switch (ad.MediaStatus)
{
case 0:
trackBar2.Enabled = trackBar1.Enabled = false;
tsbPlay.Enabled = false;
tsbPause.Enabled = false;
tsbStop.Enabled = false;
break;
case 1:
tsbPlay.Enabled = true;
tsbPause.Enabled = false;
tsbStop.Enabled = false;
break;
case 2:
tsbPlay.Enabled = true;
tsbPause.Enabled = false;
tsbStop.Enabled = true;
break;
case 3:
tsbPlay.Enabled = false;
tsbPause.Enabled = true;
tsbStop.Enabled = true;
break;
}
trackBar2.Value = ad.MediaVol;
}
/// <summary>
/// 显示歌曲总时间和播放时间
/// </summary>
private void updateSum()
{
lbSum.Text = string.Format("{0} / {1}", ad.MediaCurPos2, ad.MediaDuration2);
trackBar1.Value = ad.MediaCurPos;
}
/// <summary>
/// 歌曲计时
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
if (ad.MediaStatus == 3)
updateSum();
else if (ad.MediaStatus == 1)
{
updateToolBar();
updateSum();
}
}
/// <summary>
/// 选取音乐文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbOpen_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "All Files|*.*";
if (ofd.ShowDialog() != DialogResult.OK)
return;
ad.RenderMedia(ofd.FileName, true);
trackBar1.Maximum = ad.MediaDuration;
updateToolBar();
}
/// <summary>
/// 开始播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbPlay_Click(object sender, EventArgs e)
{
ad.Play();
updateToolBar();
}
/// <summary>
/// 暂停当前播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbPause_Click(object sender, EventArgs e)
{
ad.Pause();
updateToolBar();
}
/// <summary>
/// 结束当前播放
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbStop_Click(object sender, EventArgs e)
{
ad.Stop();
updateToolBar();
}
/// <summary>
/// 调节音乐播放进度
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void trackBar1_Scroll(object sender, EventArgs e)
{
ad.Seek(trackBar1.Value);
}
/// <summary>
/// 调节音乐声音大小
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void trackBar2_Scroll(object sender, EventArgs e)
{
ad.MediaVol = trackBar2.Value;
}
/// <summary>
/// 双击播放列表中的音乐
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_DoubleClick(object sender, EventArgs e)
{
}
}
}