C#實(shí)現(xiàn)MP3播放器功能的示例代碼
更新時(shí)間:2022年12月09日 16:50:31 作者:芝麻粒兒
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)MP3播放器功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以了解一下
實(shí)踐過(guò)程
效果
代碼
public partial class Form1 : Form { public Form1() { InitializeComponent(); } //*********************** private Point mouseOffset; //記錄鼠標(biāo)坐標(biāo) private bool isMouseDown = false; //是否按下鼠標(biāo) bool flag = false; //判斷是播放還是打開(kāi)選擇窗口 static bool MM = true; //記錄是否靜音 //*********************** private void Form1_Load(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void pictureBox2_Click(object sender, EventArgs e) { Application.Exit(); } #region 移動(dòng)無(wú)邊框窗體 private void pictureBox3_MouseDown(object sender, MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X; yOffset = -e.Y; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void pictureBox3_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void pictureBox3_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = false; } } #endregion private void pictureBox4_Click(object sender, EventArgs e) //打開(kāi)播放 { if (!flag) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { axWindowsMediaPlayer1.URL = openFileDialog1.FileName; m = 1; lblSongTitle.Text = " 歌曲名稱:" + axWindowsMediaPlayer1.currentMedia.getItemInfo("Title"); } } else { axWindowsMediaPlayer1.Ctlcontrols.play(); } } private void pictureBox5_Click(object sender, EventArgs e) //暫停 { axWindowsMediaPlayer1.Ctlcontrols.pause(); flag = true; } private void pictureBox6_Click(object sender, EventArgs e) //停止 { axWindowsMediaPlayer1.Ctlcontrols.stop(); flag = false; } private void pictureBox7_Click(object sender, EventArgs e) //靜音 { if (MM) { pictureBox7.Image = (Image) Properties.Resources.音量按鈕變色; axWindowsMediaPlayer1.settings.mute = true; MM = false; } else { pictureBox7.Image = (Image) Properties.Resources.音量按鈕; axWindowsMediaPlayer1.settings.mute = false; MM = true; } } private void pictureBox4_MouseEnter(object sender, EventArgs e) { pictureBox4.Image = (Image) Properties.Resources.播放按鈕變; } private void pictureBox4_MouseLeave(object sender, EventArgs e) { pictureBox4.Image = (Image) Properties.Resources.播放按鈕; } private void pictureBox5_MouseEnter(object sender, EventArgs e) { pictureBox5.Image = (Image) Properties.Resources.暫停按鈕變; } private void pictureBox5_MouseLeave(object sender, EventArgs e) { pictureBox5.Image = (Image) Properties.Resources.暫停按鈕; } private void pictureBox6_MouseEnter(object sender, EventArgs e) { pictureBox6.Image = (Image) Properties.Resources.停止按鈕變; } private void pictureBox6_MouseLeave(object sender, EventArgs e) { pictureBox6.Image = (Image) Properties.Resources.停止按鈕; } int m = 0; private void timer1_Tick(object sender, EventArgs e) { int i = (int) axWindowsMediaPlayer1.playState; switch (i) { case 1: lblStauts.Text = "狀態(tài):停止"; break; case 2: lblStauts.Text = "狀態(tài):暫停"; break; case 3: lblStauts.Text = "狀態(tài):播放"; break; case 6: lblStauts.Text = "狀態(tài):正在緩沖"; break; case 9: lblStauts.Text = "狀態(tài):正在連接"; break; case 10: lblStauts.Text = "狀態(tài):準(zhǔn)備就緒"; break; } lbljindu.Text = axWindowsMediaPlayer1.Ctlcontrols.currentPositionString; if (m == 1) { hScrollBar1.Maximum = (int) axWindowsMediaPlayer1.currentMedia.duration; hScrollBar1.Minimum = 0; hScrollBar1.Value = (int) axWindowsMediaPlayer1.Ctlcontrols.currentPosition; hScrollBar2.Value = axWindowsMediaPlayer1.settings.volume; } } private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) { axWindowsMediaPlayer1.Ctlcontrols.currentPosition = e.NewValue; } private void hScrollBar2_Scroll(object sender, ScrollEventArgs e) { axWindowsMediaPlayer1.settings.volume = e.NewValue; } private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e) { } }
到此這篇關(guān)于C#實(shí)現(xiàn)MP3播放器功能的示例代碼的文章就介紹到這了,更多相關(guān)C# MP3播放器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)人物旋轉(zhuǎn)和移動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01C#實(shí)現(xiàn)貨幣金額數(shù)字轉(zhuǎn)大寫漢字
這篇文章主要為大家詳細(xì)介紹了如何使用C#實(shí)現(xiàn)貨幣金額數(shù)字轉(zhuǎn)大寫漢字功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01c#調(diào)用qq郵箱smtp發(fā)送郵件修改版代碼分享
c#調(diào)用qq郵箱發(fā)送郵件的方法,網(wǎng)上找到的有錯(cuò)誤,這里修改了一下提供給大家使用2013-12-12C#基于正則表達(dá)式刪除字符串中數(shù)字或非數(shù)字的方法
這篇文章主要介紹了C#基于正則表達(dá)式刪除字符串中數(shù)字或非數(shù)字的方法,涉及C#針對(duì)數(shù)字的簡(jiǎn)單正則匹配相關(guān)操作技巧,需要的朋友可以參考下2017-06-06