-
大小: 38.55MB文件類型: .zip金幣: 1下載: 0 次發(fā)布日期: 2023-07-10
- 語(yǔ)言: C#
- 標(biāo)簽:
資源簡(jiǎn)介
C#實(shí)現(xiàn)簡(jiǎn)單的音樂(lè)播放器(只支持.wav格式文件)--帶有2個(gè).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?音樂(lè)播放器
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????List?listsongs?=?new?List();???//用來(lái)存儲(chǔ)音樂(lè)文件的全路徑
????????private?void?b_open_Click(object?sender?EventArgs?e)
????????{
????????????OpenFileDialog?ofd?=?new?OpenFileDialog();
????????????ofd.title?=?“請(qǐng)選擇音樂(lè)文件“;??????//打開(kāi)對(duì)話框的標(biāo)題
????????????ofd.InitialDirectory?=?@“F:\music“;????//設(shè)置打開(kāi)對(duì)話框的初始設(shè)置目錄
????????????ofd.Multiselect?=?true;?//設(shè)置多選
????????????ofd.Filter?=?@“音樂(lè)文件|*.mp3||*.wav|所有文件|*.*“;????//設(shè)置文件格式篩選
????????????ofd.ShowDialog();???//顯示打開(kāi)對(duì)話框
????????????string[]?pa_th?=?ofd.FileNames;???????//獲得在文件夾中選擇的所有文件的全路徑
????????????for?(int?i?=?0;?i?????????????{
????????????????listBox1.Items.Add(Path.GetFileName(pa_th[i]));??//將音樂(lè)文件的文件名加載到listBox中
????????????????listsongs.Add(pa_th[i]);????//將音樂(lè)文件的全路徑存儲(chǔ)到泛型集合中
????????????}
????????}
????????//實(shí)現(xiàn)雙擊播放
????????SoundPlayer?sp?=?new?SoundPlayer();
????????private?void?listBox1_DoubleClick(object?sender?EventArgs?e)
????????{
????????????SoundPlayer?sp?=?new?SoundPlayer();
????????????sp.SoundLocation=listsongs[listBox1.SelectedIndex];
????????????sp.Play();
????????}
????????//點(diǎn)擊下一曲
????????private?void?b_next_Click(object?sender?EventArgs?e)
????????{
????????????int?index?=?listBox1.SelectedIndex;?//獲得當(dāng)前選中歌曲的索引
????????????index++;
????????????if?(index==listBox1.Items.Count)
????????????{
????????????????index?=?0;
????????????}
????????????listBox1.SelectedIndex?=?index;?//將改變后的索引重新賦值給我當(dāng)前選中項(xiàng)的索引
????????????sp.SoundLocation?=?listsongs[index];
????????????sp.Play();
????????}
????????//點(diǎn)擊上一曲
????????private?void?b_up_Click(object?sender?EventArgs?e)
????????{
????????????int?index?=?listBox1.SelectedIndex;?//獲得當(dāng)前選中歌曲的索引
????????????index--;
????????????if?(index?<0)
????????????{
????????????????index?=?listBox1.Items.Count-1;
????????????}
????????????listBox1.SelectedIndex?=?index;?//將改變后的索引重新賦值給我當(dāng)前選中項(xiàng)的索引
????????????sp.SoundLocation?=?listsongs[index];
????????????sp.Play();
????????}
????}
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-05?20:28??音樂(lè)播放器\
?????目錄???????????0??2017-03-05?19:33??音樂(lè)播放器\bin\
?????目錄???????????0??2017-03-05?19:42??音樂(lè)播放器\bin\Debug\
?????文件???????10240??2017-03-05?20:10??音樂(lè)播放器\bin\Debug\音樂(lè)播放器.exe
?????文件???????26112??2017-03-05?20:10??音樂(lè)播放器\bin\Debug\音樂(lè)播放器.pdb
?????文件???????11600??2017-03-05?20:25??音樂(lè)播放器\bin\Debug\音樂(lè)播放器.vshost.exe
?????文件?????????490??2013-03-18?17:00??音樂(lè)播放器\bin\Debug\音樂(lè)播放器.vshost.exe.manifest
?????文件????????2813??2017-03-05?20:10??音樂(lè)播放器\Form1.cs
?????文件????????3866??2017-03-05?20:08??音樂(lè)播放器\Form1.Designer.cs
?????文件????????5817??2017-03-05?20:08??音樂(lè)播放器\Form1.resx
?????目錄???????????0??2017-03-05?19:33??音樂(lè)播放器\obj\
?????目錄???????????0??2017-03-05?19:33??音樂(lè)播放器\obj\x86\
?????目錄???????????0??2017-03-05?20:10??音樂(lè)播放器\obj\x86\Debug\
?????文件????????2855??2017-03-05?19:33??音樂(lè)播放器\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6250??2017-03-05?20:10??音樂(lè)播放器\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????目錄???????????0??2017-03-05?19:33??音樂(lè)播放器\obj\x86\Debug\TempPE\
?????文件?????????631??2017-03-05?20:25??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.csproj.FileListAbsolute.txt
?????文件?????????975??2017-03-05?20:08??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.csproj.GenerateResource.Cache
?????文件???????10240??2017-03-05?20:10??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.exe
?????文件?????????180??2017-03-05?20:08??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.Form1.resources
?????文件???????26112??2017-03-05?20:10??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.pdb
?????文件?????????180??2017-03-05?19:42??音樂(lè)播放器\obj\x86\Debug\音樂(lè)播放器.Properties.Resources.resources
?????文件?????????496??2017-03-05?19:33??音樂(lè)播放器\Program.cs
?????目錄???????????0??2017-03-05?19:33??音樂(lè)播放器\Properties\
?????文件????????1380??2017-03-05?19:33??音樂(lè)播放器\Properties\AssemblyInfo.cs
?????文件????????2882??2017-03-05?19:33??音樂(lè)播放器\Properties\Resources.Designer.cs
?????文件????????5612??2017-03-05?19:33??音樂(lè)播放器\Properties\Resources.resx
?????文件????????1102??2017-03-05?19:33??音樂(lè)播放器\Properties\Settings.Designer.cs
?????文件?????????249??2017-03-05?19:33??音樂(lè)播放器\Properties\Settings.settings
?????文件?????2513076??2016-12-25?16:49??音樂(lè)播放器\wait_jg.wav
?????文件????40489812??2015-01-09?14:06??音樂(lè)播放器\Wheel?of?Fortune幸運(yùn)之輪.wav
............此處省略3個(gè)文件信息
評(píng)論
共有 條評(píng)論