資源簡介
C#實現簡單的音樂播放器(只支持.wav格式文件)--帶有2個.wav格式文件
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;//Path類用到
using?System.Media;????//SoundPlayer命名空間
namespace?音樂播放器
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????List?listsongs?=?new?List();???//用來存儲音樂文件的全路徑
????????private?void?b_open_Click(object?sender?EventArgs?e)
????????{
????????????OpenFileDialog?ofd?=?new?OpenFileDialog();
????????????ofd.title?=?“請選擇音樂文件“;??????//打開對話框的標題
????????????ofd.InitialDirectory?=?@“F:\music“;????//設置打開對話框的初始設置目錄
????????????ofd.Multiselect?=?true;?//設置多選
????????????ofd.Filter?=?@“音樂文件|*.mp3||*.wav|所有文件|*.*“;????//設置文件格式篩選
????????????ofd.ShowDialog();???//顯示打開對話框
????????????string[]?pa_th?=?ofd.FileNames;???????//獲得在文件夾中選擇的所有文件的全路徑
????????????for?(int?i?=?0;?i?????????????{
????????????????listBox1.Items.Add(Path.GetFileName(pa_th[i]));??//將音樂文件的文件名加載到listBox中
????????????????listsongs.Add(pa_th[i]);????//將音樂文件的全路徑存儲到泛型集合中
????????????}
????????}
????????//實現雙擊播放
????????SoundPlayer?sp?=?new?SoundPlayer();
????????private?void?listBox1_DoubleClick(object?sender?EventArgs?e)
????????{
????????????SoundPlayer?sp?=?new?SoundPlayer();
????????????sp.SoundLocation=listsongs[listBox1.SelectedIndex];
????????????sp.Play();
????????}
????????//點擊下一曲
????????private?void?b_next_Click(object?sender?EventArgs?e)
????????{
????????????int?index?=?listBox1.SelectedIndex;?//獲得當前選中歌曲的索引
????????????index++;
????????????if?(index==listBox1.Items.Count)
????????????{
????????????????index?=?0;
????????????}
????????????listBox1.SelectedIndex?=?index;?//將改變后的索引重新賦值給我當前選中項的索引
????????????sp.SoundLocation?=?listsongs[index];
????????????sp.Play();
????????}
????????//點擊上一曲
????????private?void?b_up_Click(object?sender?EventArgs?e)
????????{
????????????int?index?=?listBox1.SelectedIndex;?//獲得當前選中歌曲的索引
????????????index--;
????????????if?(index?<0)
????????????{
????????????????index?=?listBox1.Items.Count-1;
????????????}
????????????listBox1.SelectedIndex?=?index;?//將改變后的索引重新賦值給我當前選中項的索引
????????????sp.SoundLocation?=?listsongs[index];
????????????sp.Play();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-05?20:28??音樂播放器\
?????目錄???????????0??2017-03-05?19:33??音樂播放器\bin\
?????目錄???????????0??2017-03-05?19:42??音樂播放器\bin\Debug\
?????文件???????10240??2017-03-05?20:10??音樂播放器\bin\Debug\音樂播放器.exe
?????文件???????26112??2017-03-05?20:10??音樂播放器\bin\Debug\音樂播放器.pdb
?????文件???????11600??2017-03-05?20:25??音樂播放器\bin\Debug\音樂播放器.vshost.exe
?????文件?????????490??2013-03-18?17:00??音樂播放器\bin\Debug\音樂播放器.vshost.exe.manifest
?????文件????????2813??2017-03-05?20:10??音樂播放器\Form1.cs
?????文件????????3866??2017-03-05?20:08??音樂播放器\Form1.Designer.cs
?????文件????????5817??2017-03-05?20:08??音樂播放器\Form1.resx
?????目錄???????????0??2017-03-05?19:33??音樂播放器\obj\
?????目錄???????????0??2017-03-05?19:33??音樂播放器\obj\x86\
?????目錄???????????0??2017-03-05?20:10??音樂播放器\obj\x86\Debug\
?????文件????????2855??2017-03-05?19:33??音樂播放器\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6250??2017-03-05?20:10??音樂播放器\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2017-03-05?19:33??音樂播放器\obj\x86\Debug\TempPE\
?????文件?????????631??2017-03-05?20:25??音樂播放器\obj\x86\Debug\音樂播放器.csproj.FileListAbsolute.txt
?????文件?????????975??2017-03-05?20:08??音樂播放器\obj\x86\Debug\音樂播放器.csproj.GenerateResource.Cache
?????文件???????10240??2017-03-05?20:10??音樂播放器\obj\x86\Debug\音樂播放器.exe
?????文件?????????180??2017-03-05?20:08??音樂播放器\obj\x86\Debug\音樂播放器.Form1.resources
?????文件???????26112??2017-03-05?20:10??音樂播放器\obj\x86\Debug\音樂播放器.pdb
?????文件?????????180??2017-03-05?19:42??音樂播放器\obj\x86\Debug\音樂播放器.Properties.Resources.resources
?????文件?????????496??2017-03-05?19:33??音樂播放器\Program.cs
?????目錄???????????0??2017-03-05?19:33??音樂播放器\Properties\
?????文件????????1380??2017-03-05?19:33??音樂播放器\Properties\AssemblyInfo.cs
?????文件????????2882??2017-03-05?19:33??音樂播放器\Properties\Resources.Designer.cs
?????文件????????5612??2017-03-05?19:33??音樂播放器\Properties\Resources.resx
?????文件????????1102??2017-03-05?19:33??音樂播放器\Properties\Settings.Designer.cs
?????文件?????????249??2017-03-05?19:33??音樂播放器\Properties\Settings.settings
?????文件?????2513076??2016-12-25?16:49??音樂播放器\wait_jg.wav
?????文件????40489812??2015-01-09?14:06??音樂播放器\Wheel?of?Fortune幸運之輪.wav
............此處省略3個文件信息
評論
共有 條評論