| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2650 人关注过本帖
标题:怎么写listbox双击播放音乐
只看楼主 加入收藏
mz1095380738
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2016-11-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
怎么写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)
{

}





}
}
搜索更多相关主题的帖子: 播放器 private public null 音乐 
2016-11-27 17:44
over1230
Rank: 8Rank: 8
等 级:贵宾
威 望:25
帖 子:113
专家分:897
注 册:2009-10-9
收藏
得分:20 
listbox获取名称,然后播放。
和文件选择一样,只是获取名称的方式变了。
2016-11-28 11:38
快速回复:怎么写listbox双击播放音乐
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016875 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved