用C#开发的简单MP3播放器

上传人:ta****u 文档编号:177603643 上传时间:2022-12-26 格式:DOCX 页数:17 大小:255.60KB
返回 下载 相关 举报
用C#开发的简单MP3播放器_第1页
第1页 / 共17页
用C#开发的简单MP3播放器_第2页
第2页 / 共17页
用C#开发的简单MP3播放器_第3页
第3页 / 共17页
点击查看更多>>
资源描述
一、软件说明:功能说明:一个简易小巧的 MP3 播放器,可以播放已经下载 好的 MP3 格式的音乐。解决什么样的实际问题:市场上的音乐播放器大都占用资源比 较大,而且需要联网,即使播放本地音乐,也会占用较多的网速,而 这款播放器解决了这些问题。(虽然还是有很多缺陷,但用起来还是 比较方便的。)性能说明:可以播放单首或多首歌曲,可以保存或清空当前播放列表,支持列表循环,顺序播放,单曲循环。(但目前只支持 MP3 格式。)程序类型说明:这个播放器是winform应用程序。二、软件设计软件整体结构图及模块划分:软件整体结构图:MusicplayerA Li t tie Love, mp3CIlT 1 e tn az In M j-mp-JEverytime, mp3Liwing T0 Lowe You. mjiJLove ?:ii-:diEe. mp3LkldIty Twi c e 一 Me AtliI You. mp3 MorniiLg. mp3Trael i y Li 吐lt. mp3Truublc Is A Friymi. mp3控制模块:歌曲列表显示区:A. Li ttlm Lave. mTiSC til-i stnas In fily Hr art.阡 pdEvery! ime. mp3Living To Love Tuu. mpSLove F :ii:-:=Lili e e. mji3Lucky Twice 一 M Arni i cm. mp3M orni n p;. mp3Trsveling Li ght. mp3Ti:uble Is A Fi_iend. mp3Wieh i .:.u Xu色 Ht-5. rTif.3You :iiid Me. mp3Th. nip3二噩畫驢幣 七里番,mp3在 VS 的“解决方案资源管理器”中的文件说明 整个项目的文件如下:易解决方案MyWlu衆P怙y”(1个项目) n 副 MyMusicPlayer 国 Pro pert ies.曲引用I坐 app.conEgForml.CE.| Program.es其中,Properties中所包含的的文件有:J _j Properties酋 Asseniblylnfcr,c5. 倉 Re&OLirce&.resx 回 Settings.settings这里包含的是定义程序集属性的文件,用来设定生成的有关程序集的常规信息dll文件的一些参数。引用中包含的文件有:j j引用Q AxWMPLibQ Microsoft.C&harpQ System口 System .CoreJP3P3P3天着P3六壬闰 naw m m mi mi 1n抱 心风味挂地P3的miZ2. m勾El Mu sic PlayerP3143 - p p e 3 m .p - 友皿人量两m上m3 p 歌我s 妊莘P3唱P3P3半 MP3P3肘你I m mor 工果单hhm3 3 p p me 養P3文祥亦测试情况分析经测试,软件运行情况基本良好,但单曲循环功能有些缺陷,有待改进,总体情况还算良好。四、小结这一次的课程设计开发的这个软件是我的第一个软件,看到它能 够基本实现我想要的功能,感到非常开心,尽管还有很多缺陷。在做这个软件的时候,遇到过很多问题,一开始觉得有问题上网 找就是了,但在做的的时候却并不是如此,上网百度,用C#开发的 播放器源码很多,教程也不少,但都讲的很乱,而且那些属性名,控 件名,方法名之类的都和自己的不同,原理不懂,给你源码也没用。 没办法, 就只能恶补, 像各种控件的 属性, 尤其是 axWindowsmediaPlayer 控件的各种属性及使用方法(这也是我这次 课程设计最大的收获。),文件处理等。通过这次课程设计,我学到了很多课堂和书本学不到的东西,我 觉得最重要的一点就是注意细节以及动手之前弄懂基本原理。五、附录用到的第三方控件或组件说明: 这个程序用到的第三方控件是 axWindowsmediaPlayer 控件,这个 控件是一个 COM 组件,是 windows 自带的控件,用于播放媒体文 件,在开发媒体播放器时使用是非常方便的。程序的主要代码(对应上面第二条):窗体设计代码 From1.cs:using System;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text; usingSystem.Windows.Forms; using System.IO;namespaceMyMusicPlayerpublicpartialclassMusicPlayer : FormpublicMusicPlayer()InitializeComponent();string musicPath = newstring1000; /用于保存歌曲目录 intmusicCount = 0;privatevoid Form1_Load(object sender, EventArgs e)myPlayer.BeginInit(); /初始化 myPlayer.settings.autoStart = true; /自动播放 myPlayer.settings.setMode(shuffle, false); /顺序播放 myPlayer.settings.enableErrorDialogs = true;myPlayer.settings.balance = 0;myPlayer.settings.mute = false;myPlayer.settings.volume = 100; /声音 设为最大if (File.Exists(listbox.txt) /如果存在播放列表,那么加载播放列表 StreamReader reader = newStreamReader(listbox.txt); trywhile (reader.Peek() != -1)stringfilepath = reader.ReadLine();if (File.Exists(filepath)musicPathmusicCount+ = filepath;string filename = Path.GetFileName(filepath);listBoxl. Items.Add(filename); /listbox用来显示歌 曲名myPlayer.currentPlaylist.insertItem(myPlayer.currentPlaylist.count, myPlayer.newMedia(filepath);listBox1.SelectedIndex = 0;catch (Exception) listBox1.SelectedIndex = -1;MessageBox.Show(加载播放列表失败或者列表为空!,提示,MessageBoxButtons.OK, MessageBoxIcon.Error);finally reader.Close();privatevoid打开文件ToolStripMenulteml_Click(object sender, EventArgs e)/打开单 首歌曲,但不加载到播放列表DialogResultdr = openFileDialog1.ShowDialog();if (dr =DialogResult.OK)myPlayer.URL = openFileDialog1.FileName;privatevoid添加歌曲ToolStripMenultem_Click(object sender, EventArgs e)/打开单首 歌曲,并加载到播放列表DialogResultdr = openFileDialog1.ShowDialog();if (dr =DialogResult.OK)myPlayer.URL = openFileDialog1.FileName; stringfilepath = openFileDialog1.FileName;string filename =Path.GetFileName(filepath); listBox1.Items.Add(filename);musicPathmusicCount+ = filepath; myPlayer.currentPlaylist.insertItem(myPlayer.currentPlaylist.count, myPlayer.newMedia(filepath);privatevoid添加文件夹ToolStripMenultem_Click(object sender, EventArgse)/打开媒 体文件夹,并加载到播放列表DialogResultdr = folderBrowserDialog1.ShowDialog();if (dr = DialogResult.OK)string filepath = Directory.GetFiles(folderBrowserDialog1.SelectedPath); foreach (strings infilepath)if (Path.GetExtension(s) = .mp3)string filename = Path.GetFileName(s); listBox1.Items.Add(filename);musicPathmusicCount+ = s; myPlayer.currentPlaylist.insertItem(myPlayer.currentPlaylist.count, myPlayer.newMedia(s);privatevoid退出ToolStripMenultem_Click(object sender, EventArgs e)/退出播放器并 保存当前播放列表myPlayer.Ctlcontrols.stop();myPlayer.close();StreamWriter writer =newStreamWriter(listbox.txt,false,Encoding.Unicode); /保存播放列表for (inti = 0; i= musicCount - 1; i+)if (musicPathi !=string.Empty)writer.WriteLine(musicPathi); writer.Close();Application.Exit();privatevoid axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e) /显示播放状态if (myPlayer.playState = WMPLib.WMPPlayState.wmppsPlaying)string s = myPlayer.currentMedia.sourceURL;for (inti = 0; imyPlayer.currentPlaylist.count; i+)if (listBox1.Itemsi.ToString() =Path.GetFileName(s)listBox1.SelectedIndex = i;break;privatevoid清空列表ToolStripMenulteml_Click(object sender, EventArgs e)/清空当 前播放列表myPlayer.Ctlcontrols.stop(); /先停止播放器lis tBoxl. It ems.Clear(); /清空 list box myPlayer.currentPlaylist.clear(); /清空播放列表 for (int j = 0; j musicCount; j+)musicPathj =;privatevoid Form1_KeyPress(object sender, KeyPressEventArgs e)if (char.Equals(e.KeyChar, )if (myPlayer.playState = WMPLib.WMPPlayState.wmppsPlaying)myPlayer.Ctlcontrols.pause();privatevoid顺序播放ToolStripMenuItem_Click(object sender, EventArgs e)/按列表顺 序播放歌曲文件myPlayer.settings.playCount = 1; myPlayer.currentPlaylist.clear();for (int j = 0; j 0)int k = listBox1.SelectedIndex;for (inti = 0; i 1000; i+) myPlayer.currentPlaylist.insertItem(myPlayer.currentPlaylist.count, myPlayer.newMedia(musicPathk); myPlayer.Ctlcontrols.playItem(myPlayer.currentPlaylist.get_Item(0);privatevoid随机播放ToolStripMenuItem_Click(object sender, EventArgs e)/随机播放 列表歌曲文件myPlayer.settings.playCount = 1; myPlayer.Ctlcontrols.stop();myPlayer.currentPlaylist.clear();Randomrd =newRandom(DateTime.Now.Millisecond); for (inti = 0; i0&listBox1.SelectedIndex=0) myPlayer.Ctlcontrols.playItem(myPlayer.currentPlaylist.get_Item(listBox1.Select edIndex);程序入口代码Program.cs:using System;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Windows.Forms; usingSystem.Runtime.InteropServices; using Microsoft.Win32; usingSystem.Threading;namespaceMyMusicPlayerstaticclassProgram/*显示已经运行程序的主界面*/DllImport(user32.dll, EntryPoint = ShowWindow) staticexternboolShowWindow(IntPtr handle, int flags);/显示窗口DllImport(user32.dll, EntryPoint = SetForegroundWindow) staticexternboolSetForegroundWindow(IntPtr handle);/将窗口置最前/应用程序的主入口点。/STAThread staticvoid Main()Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(newMusicPlayer();
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑环境 > 建筑资料


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!