码迷,mamicode.com
首页 > Windows程序 > 详细

winform下的简易播放器

时间:2016-03-18 21:38:04      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:

技术分享编写这个播放器,遇到很多问题,比如目前只实现了wav音频文件的播放,而对于这个图中中间所标注的按钮

不能实现让其暂停的功能,同时当点击的时候,让其文本变为"?",对于这部分功能不知道选定该按钮时的属性是

如何,所以还需继续完善

技术分享播放器代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 using System.Media;
 11 using System.IO;
 12 
 13 namespace WindowsFormsApplication1
 14 {
 15     public partial class Form1 : Form
 16     {
 17         public Form1()
 18         {
 19             InitializeComponent();
 20         }
 21 
 22         private void Form1_Load(object sender, EventArgs e)
 23         {
 24            
 25         }
 26         List<string> listSongs = new List<string>();//定义存储歌名的路径泛型变量
 27         private void button5_Click(object sender, EventArgs e)
 28         {
 29             OpenFileDialog ofd = new OpenFileDialog();
 30             ofd.Title = "请选择音频文件";
 31             ofd.InitialDirectory =@"F:\wav_music";
 32             ofd.Filter="音频文件|*.wav|所有文件|*.*";
 33             ofd.Multiselect=true;//多选设置
 34             ofd.ShowDialog();
 35             string[] path = ofd.FileNames;//获取音频文件的全路径
 36             for (int i = 0; i < path.Length; i++)
 37             {
 38                 listBox1.Items.Add(Path.GetFileName(path[i]));//将获取到的文件路径截取文件名并添加到listbox中
 39                 listSongs.Add(path[i]);//将路径添加到list集合当中
 40 
 41             }
 42                
 43 
 44         }
 45         /// <summary>
 46         /// 双击播放音乐方法。
 47         /// </summary>
 48         /// <param name="sender"></param>
 49         /// <param name="e"></param>
 50       
 51         private void listBox1_DoubleClick(object sender, EventArgs e)
 52         {
 53             SoundPlayer sp = new SoundPlayer();//
 54             sp.SoundLocation = listSongs[listBox1.SelectedIndex];
 55             sp.Play();
 56         }
 57         /// <summary>
 58         /// 播放下一首
 59         /// </summary>
 60         /// <param name="sender"></param>
 61         /// <param name="e"></param>
 62 
 63         private void button4_Click(object sender, EventArgs e)
 64         {
 65             //获取当前所选定的音乐项
 66             int index = listBox1.SelectedIndex;
 67             index++;
 68             SoundPlayer sp = new SoundPlayer();
 69             if (index ==listSongs.Count)
 70             {
 71 
 72                 index = 0;
 73             }
 74             listBox1.SelectedIndex = index;//将索引重新赋值给listbox选定。
 75             sp.SoundLocation = listSongs[index];
 76             sp.Play();
 77            
 78                
 79             
 80            
 81            
 82         }
 83         /// <summary>
 84         /// 播放上一首
 85         /// </summary>
 86         /// <param name="sender"></param>
 87         /// <param name="e"></param>
 88         
 89         private void button2_Click(object sender, EventArgs e)
 90         {
 91             //获取当前所选定的音乐项
 92             int index = listBox1.SelectedIndex;
 93             index--;
 94             SoundPlayer sp = new SoundPlayer();
 95             if (index ==0 )
 96             {
 97                 index = listSongs.Count - 1;
 98             }
 99             listBox1.SelectedIndex = index;
100             sp.SoundLocation = listSongs[index];
101             sp.Play();
102 
103         }
104     }
105 }

 

winform下的简易播放器

标签:

原文地址:http://www.cnblogs.com/dwj2012/p/5293385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!