C# 一款属于自己的音乐播放器
发布时间:2020-12-16 01:13:20 所属栏目:百科 来源:网络整理
导读:本文利用C# 调用Windows自带的Windows Media Player 打造一款属于自己的音乐播放器,以供学习分享使用,如有不足之处,还请指正。 概述 Windows Media Player是微软公司出品的一款免费的播放器,属于Microsoft Windows的一个组件,通常简称"WMP",支持通过插
本文利用C# 调用Windows自带的Windows Media Player 打造一款属于自己的音乐播放器,以供学习分享使用,如有不足之处,还请指正。 概述Windows Media Player是微软公司出品的一款免费的播放器,属于Microsoft Windows的一个组件,通常简称"WMP",支持通过插件增强功能。版本Windows Media Player 12 随 Windows 7及以上提供。可以播放MP3,WMA,WAV等音频文件。本文音乐播放器,主要是MP3文件。 涉及知识点
设计思路
添加Windows Media Player组件工具--》选择工具箱项--》COM组件--》Windows Media Player,如下图所示: 音乐播放器效果图音乐播放器效果图如下图所示 核心代码加载皮肤 1 /// <summary> 2 /// 初始化皮肤 3 </summary> 4 private void InitInfo() 5 { 6 this.skinEngine = new SkinEngine(); 7 this.skinEngine.SkinFile = AppDomain.CurrentDomain.BaseDirectory + @"Skinsmp10.ssk"; 8 this.skinEngine.DisableTag = 9999 9 ReadSkinFile(); 10 } 切换背景图 1 背景图切换 4 <param name="sender"></param> 5 <param name="e"></param> 6 void BgWorker1_DoWork(object sender,DoWorkEventArgs e) 7 while (isRunning) { 9 if (bgUrls != null && bgUrls.Length > 0) { 10 this.curIndex = (this.curIndex % bgUrls.Length); 11 this.pbImage.Image = Image.FromStream(HttpWebRequest.Create(bgUrls[this.curIndex]).GetResponse().GetResponseStream()); 12 this.pbImage.SizeMode = PictureBoxSizeMode.StretchImage; 13 this.curIndex++14 // 15 this.lblTime.Invoke(new Action(() => 16 { 17 this.lblTime.Text = string.Format("{0}/{1}",this.axWindowsMediaPlayer1.Ctlcontrols.currentPositionString,1)">.axWindowsMediaPlayer1.currentMedia.durationString); 18 //this.lblTime.ForeColor = Color.White; 19 })); 20 21 } 22 Thread.Sleep(2000); 23 } 24 } AxWindowsMediaPlayer相关属性方法 1 [基本属性] 2 URL:String; 指定媒体位置,本机或网络地址 3 uiMode:String; 播放器界面模式,可为Full,Mini,None,Invisible 4 playState:integer; 播放状态,1=停止,2=暂停,3=播放,6=正在缓冲,9=正在连接,10=准备就绪 5 enableContextMenu:Boolean; 启用/禁用右键菜单 6 fullScreen:boolean; 是否全屏显示 播放器基本控制 8 Ctlcontrols.play; 播放 Ctlcontrols.pause; 暂停 10 Ctlcontrols.stop; 停止 11 Ctlcontrols.currentPosition:double; 当前进度 12 Ctlcontrols.currentPositionString:string; 当前进度,字符串格式。如“00:23” 13 Ctlcontrols.fastForward; 快进 14 Ctlcontrols.fastReverse; 快退 15 Ctlcontrols.next; 下一曲 Ctlcontrols.previous; 上一曲 17 [settings] wmp.settings 播放器基本设置 18 settings.volume:integer; 音量,0-100 settings.autoStart:Boolean; 是否自动播放 20 settings.mute:Boolean; 是否静音 settings.playCount:integer; 播放次数 22 [currentMedia] wmp.currentMedia 当前媒体属性 23 currentMedia.duration:; 媒体总长度 24 currentMedia.durationString:string; 媒体总长度,字符串格式。如“03:2425 currentMedia.getItemInfo(const string); 获取当前媒体信息Title"=媒体标题,Author"=艺术家,Copyright"=版权信息,Description"=媒体内容描述, Duration"=持续时间(秒),FileSize"=文件大小,FileType"=文件类型,sourceURL"=原始地址 26 currentMedia.setItemInfo(string); 通过属性名设置媒体信息 27 currentMedia.name:string; 同 currentMedia.getItemInfo() 28 [currentPlaylist] wmp.currentPlaylist 当前播放列表属性 29 currentPlaylist.count:integer; 当前播放列表所包含媒体数 30 currentPlaylist.Item[integer]; 获取或设置指定项目媒体信息,其子属性同wmp.currentMedia 31 axWindowsMediaPlayer1.currentMedia.sourceURL; 获取正在播放的媒体文件的路径 32 axWindowsMediaPlayer1.currentMedia.name; 获取正在播放的媒体文件的名称 33 axWindowsMediaPlayer1.Ctlcontrols.Play 播放 34 axWindowsMediaPlayer1.Ctlcontrols.Stop 停止 35 axWindowsMediaPlayer1.Ctlcontrols.Pause 暂停 36 axWindowsMediaPlayer1.Ctlcontrols.PlayCount 文件播放次数 37 axWindowsMediaPlayer1.Ctlcontrols.AutoRewind 是否循环播放 38 axWindowsMediaPlayer1.Ctlcontrols.Balance 声道 39 axWindowsMediaPlayer1.Ctlcontrols.Volume 音量 40 axWindowsMediaPlayer1.Ctlcontrols.Mute 静音 41 axWindowsMediaPlayer1.Ctlcontrols.EnableContextMenu 是否允许在控件上点击鼠标右键时弹出快捷菜单 42 axWindowsMediaPlayer1.Ctlcontrols.AnimationAtStart 是否在播放前先播放动画 43 axWindowsMediaPlayer1.Ctlcontrols.ShowControls 是否显示控件工具栏 44 axWindowsMediaPlayer1.Ctlcontrols.ShowAudioControls 是否显示声音控制按钮 45 axWindowsMediaPlayer1.Ctlcontrols.ShowDisplay 是否显示数据文件的相关信息 46 axWindowsMediaPlayer1.Ctlcontrols.ShowGotoBar 是否显示Goto栏 47 axWindowsMediaPlayer1.Ctlcontrols.ShowPositionControls 是否显示位置调节按钮 48 axWindowsMediaPlayer1.Ctlcontrols.ShowStatusBar 是否显示状态栏 49 axWindowsMediaPlayer1.Ctlcontrols.ShowTracker 是否显示进度条 50 axWindowsMediaPlayer1.Ctlcontrols.FastForward 快进 51 axWindowsMediaPlayer1.Ctlcontrols.FastReverse 快退 52 axWindowsMediaPlayer1.Ctlcontrols.Rate 快进/快退速率 53 axWindowsMediaPlayer1.AllowChangeDisplaySize 是否允许自由设置播放图象大小 54 axWindowsMediaPlayer1.DisplaySize 设置播放图象大小 55 1-MpDefaultSize 原始大小 56 2-MpHalfSize 原始大小的一半 57 3-MpDoubleSize 原始大小的两倍 58 4-MpFullScreen 全屏 59 5-MpOneSixteenthScreen 屏幕大小的1/16 60 6-MpOneFourthScreen 屏幕大小的1/4 61 7-MpOneHalfScreen 屏幕大小的1/2 62 axWindowsMediaPlayer1.ClickToPlay 是否允许单击播放窗口启动Media Player 备注关于AxWindowsMediaPlayer的属性方法,也可以参考豆丁文档。 源码下载链接 ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |