音樂播放器c#實際運用_第1頁
音樂播放器c#實際運用_第2頁
音樂播放器c#實際運用_第3頁
音樂播放器c#實際運用_第4頁
音樂播放器c#實際運用_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、namespace WindowsFormsApplication4 public partial class Form1 : Form #region public Form1() InitializeComponent(); #endregion #region 停止鍵 private void button3_Click(object sender, EventArgs e) musicPlayer.Ctlcontrols.stop(); #endregion #region 默認(rèn)設(shè)置 private void Form1_Load(object sender, EventArgs e)

2、 /默認(rèn)皮膚 skinEngine1.SkinFile = skinVISTA1.SSK; /默認(rèn)圖片 pictureBox1.Image = Image.FromFile(Images1.jpg); /調(diào)整大小不一致 pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; /關(guān)閉自動播放 musicPlayer.settings.autoStart = false; #endregion #region 點多了不知道怎么刪 private void skinEngine1_CurrentSkinChanged(object sender

3、, Sunisoft.IrisSkin.SkinChangedEventArgs e) #endregion #region 每兩秒自動換圖片 int j = 0; private void timer1_Tick(object sender, EventArgs e) string imgPath = Directory.GetFiles(Images); j+; if (j = imgPath.Length) j = 0; pictureBox1.Image = Image.FromFile(imgPathj); #endregion #region 換膚鍵 int i = 0; priv

4、ate void button1_Click(object sender, EventArgs e) string skinPath = Directory.GetFiles(skin); i+; if (i = skinPath.Length) i = 0; skinEngine1.SkinFile = skinPathi; #endregion #region 播放暫停鍵 private void button2_Click(object sender, EventArgs e) if (button2.Text = 播放) musicPlayer.Ctlcontrols.play();

5、button2.Text = 暫停; else if (button2.Text = 暫停) musicPlayer.Ctlcontrols.pause(); button2.Text = 播放; #endregion #region 選擇文件鍵 /創(chuàng)建集合 List listSongs = new List(); private void button4_Click(object sender, EventArgs e) /創(chuàng)建打開文件對話框?qū)ο?OpenFileDialog ofd = new OpenFileDialog(); /設(shè)置對話框的標(biāo)題 ofd.Title = 請選擇音樂文件;

6、 /設(shè)置對話框可以多選 ofd.Multiselect = true; /設(shè)置打開文件類型 ofd.Filter = 音樂文件|*.mp3|所有文件|*.*; /設(shè)置打開文件的初始路徑 ofd.InitialDirectory = Songs; /顯示對話框 ofd.ShowDialog(); /獲得對話框中選中文件的全路徑 string filePath = ofd.FileNames; for (int i = 0; i filePath.Length; i+) /將路徑存儲到泛型集合listSongs中 listSongs.Add(filePathi); /將文件名顯示在ListBox控

7、件中 listBox1.Items.Add(Path.GetFileName(filePathi); #endregion #region 上一曲 private void button5_Click(object sender, EventArgs e) int index = listBox1.SelectedIndex; listBox1.SelectedIndices.Clear(); if (index = -1) return; index-; if (index =-1) index = listBox1.Items.Count-1; listBox1.SelectedIndex

8、 = index; musicPlayer.URL = listSongsindex; musicPlayer.Ctlcontrols.play(); button2.Text = 暫停; /加載歌詞 LoadLrc(); #endregion #region 雙擊播放 private void listBox1_DoubleClick(object sender, EventArgs e) if (listBox1.SelectedIndex = -1) return; musicPlayer.URL = listSongslistBox1.SelectedIndex; musicPlaye

9、r.Ctlcontrols.play(); button2.Text = 暫停; /加載歌詞 LoadLrc(); #endregion #region 歌詞加載函數(shù) private void LoadLrc() /根據(jù)正在播放的歌曲獲取相應(yīng)的歌詞文件 string songPath = listSongslistBox1.SelectedIndex; string lrcPath = songPath + .lrc; if (File.Exists(lrcPath) string lrcText = File.ReadAllLines(lrcPath, Encoding.Default);

10、/將歌詞文件的信息提取出來,分別處理 FormatLrc(lrcText); else /不存在歌詞文件 label1.Text = =歌詞未找到=; listTime.Clear(); listLrc.Clear(); /存儲時間 List listTime = new List(); /存儲歌詞 List listLrc = new List(); private void FormatLrc(string lrcText) /00:18.58今天我 寒夜里看雪飄過 /lrcTemp0:00:18.58 /lrcTemp1:今天我 寒夜里看雪飄過 for (int i = 0; i lrc

11、Text.Length; i+) string lrcTemp = lrcTexti.Split(new char , , StringSplitOptions.RemoveEmptyEntries); listLrc.Add(lrcTemp1); /00:18.58 /lrcNewTemp0 00 /lrcNewTemp1 18.58 string lrcNewTemp = lrcTemp0.Split(new char : , StringSplitOptions.RemoveEmptyEntries); double time = double.Parse(lrcNewTemp0) *

12、60 + double.Parse(lrcNewTemp1); listTime.Add(time); #endregion #region 下一曲 private void button6_Click(object sender, EventArgs e) int index = listBox1.SelectedIndex; listBox1.SelectedIndices.Clear(); if (index = -1) return; index+; if (index = listBox1.Items.Count) index = 0; listBox1.SelectedIndex

13、= index; musicPlayer.URL = listSongsindex; musicPlayer.Ctlcontrols.play(); button2.Text = 暫停; /加載歌詞 LoadLrc(); #endregion #region 右鍵上下欄刪除功能 private void 刪除ToolStripMenuItem_Click(object sender, EventArgs e) /獲得需要刪除的歌曲數(shù)量 int count = listBox1.SelectedItems.Count; for (int i = 0; i count; i+) /先刪除集合lis

14、tSongs listSongs.RemoveAt(listBox1.SelectedIndex); /后刪除列表 listBox1.Items.RemoveAt(listBox1.SelectedIndex); #endregion #region 自動下一曲 private void timer2_Tick(object sender, EventArgs e) /判斷當(dāng)前歌曲是否處于播放狀態(tài) if (musicPlayer.playState = WMPLib.WMPPlayState.wmppsPlaying) if (musicPlayer.currentMedia.duration

15、 - musicPlayer.Ctlcontrols.currentPosition = 1) /播放下一曲 int index = listBox1.SelectedIndex; listBox1.SelectedIndices.Clear(); if (index = -1) return; index+; if (index = listBox1.Items.Count) index = 0; listBox1.SelectedIndex = index; musicPlayer.URL = listSongsindex; musicPlayer.Ctlcontrols.play();

16、button2.Text = 暫停; /加載歌詞 LoadLrc(); #endregion #region 顯示歌詞 private void timer3_Tick(object sender, EventArgs e) double currentTime = musicPlayer.Ctlcontrols.currentPosition; for (int i = 0; i = listTimei & currentTime listTimei + 1) label1.Text = listLrci; #endregion #region 窗體縮小顯示圖標(biāo) private void F

17、orm1_Resize(object sender, EventArgs e) /判斷form大小做出相應(yīng)事件反應(yīng) if (this.WindowState=FormWindowState.Minimized) this.ShowInTaskbar = false; notifyIcon1.Visible = true; else this.ShowInTaskbar = true; notifyIcon1.Visible = false; #endregion #region 小圖標(biāo)雙擊事件,復(fù)原 private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) this.WindowState = FormWindowState.Normal; #endregion #region 又是刪不了的 private void contextMenuStrip2

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論