用WindowsMediaPlayer控件写个WinForm播放器
用WindowsMediaPlayer控件写了一个小播放器,只是一个小尝试
首先要添加Windows Media Player到工具箱
右击工具箱->选择项(I)... -> 显示"选择工具箱项" -> COM组件 -> Windows Media Player wmp.dll 添加
然后拖了一个 Windows Media Player控件、两个按钮、一个ListBox。
附:
private void button1_Click(object sender, EventArgs e) { AddMusicToListBox(listBox1); } private void AddMusicToListBox(ListBox lb) { string[] files = GetMusicFiles(); if (files != null && files.Length > 0) { foreach (string file in files) { if (!lb.Items.Contains(file)) { lb.Items.Add(file); } } } } private string[] GetMusicFiles() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true;//设置 选择多个文件 ofd.InitialDirectory = @"G:\MUSIC"; ofd.Filter = "(MP3文件)|*.mp3"; if (ofd.ShowDialog() == DialogResult.OK) { return ofd.FileNames; } else { return null; } } private void listBox1_DoubleClick(object sender, EventArgs e) { axWindowsMediaPlayer1.currentPlaylist.clear(); //MessageBox.Show(listBox1.SelectedItem.ToString()); WMPLib.IWMPMedia song = axWindowsMediaPlayer1.newMedia(listBox1.SelectedItem.ToString()); axWindowsMediaPlayer1.currentPlaylist.appendItem(song); axWindowsMediaPlayer1.Ctlcontrols.play(); } private void button2_Click(object sender, EventArgs e) { RemoveMusicFromListBox(listBox1); } private void RemoveMusicFromListBox(ListBox lb) { lb.Items.Remove(lb.SelectedItem); }
本博客(liqipeng)除非已明确说明转载,否则皆为liqipeng原创或者整理,转载请保留此链接:https://www.cnblogs.com/liqipeng/archive/2012/07/03/4584792.html。
本博客(liqipeng)除非已明确说明转载,否则皆为liqipeng原创或者整理,转载请保留此链接:https://www.cnblogs.com/liqipeng/archive/2012/07/03/4584792.html。
如果你觉得这篇文章对你有帮助或者使你有所启发,请点击右下角的推荐按钮,谢谢,:)