音乐播放器程序源代码及注释
关于C语言播放音乐的源代码
关于C语⾔播放⾳乐的源代码我们不得不说C语⾔是⼀种还算得上强⼤的语⾔,今天就来展⽰⼀下如何通过C语⾔去播放⾳乐:⽹上有很多这⽅⾯的资料,我只是稍加整理了⼀下,随便玩⼀下。
先来看第⼀个例程,这是⽐较简单的:#include<stdio.h>#include<dos.h>#include<bios.h>#include<time.h>#include<graphics.h>#define N1 32 /*⼀拍*/#define N2 16#define N4 8#define N8 4#define N16 2#define END 0/*其中:N1,N2,N4,N6,N8,N16分别代表⼀拍,⼆分之⼀拍,四分之⼀拍,⼋分之⼀拍,⼗六分之⼀拍。
*//*声明⼀个图形显⽰*/void printtext(unsigned char *temp[],int i, int color); /* ⽤于在屏幕上显⽰字符串 */enum NOTES{C10=131,D10=147,E10=165,F10=175,G10=196,A10=220,B10=247,/*低度⾳调分别是:1,2,3,4,5,6,7*/C0=262, D0=286, E0=330, F0=349, G0=440, A0=440, B0=494,/*中度⾳调分别是:1,2,3,4,5,6,7*/C1=523, D1=158, E1=659, F1=698, G1=784, A1=880, B1=998,/*⾼度⾳调分别是:1,2,3,4,5,6,7*/C2=1047,D2=1175,E2=1319,F2=1397,G2=1568,A2=1760,B2=1976/*⾼⼋度⾳调分别是:1,2,3,4,5,6,7*/}song1[]={G0,N16,G0,N8,A0,N8,G0,N8,C1,N8,B0,N4,G0,N16,G0,N8,A0,N8,G0,N8,D1,N8,C1,N4,G0,N16,G0,N8,G1,N8,E1,N8,C1,N8,B0,N16,B0,N8,A0,N4,F1,N16,F1,N8,E1,N8,C1,N8,D1,N8,C1,N4,END,END/*以上是曲⼦代码,你可以嵌⼊⾃⼰喜欢的歌曲代码*//*注意:数组中的偶数元素代表⾳符奇数元素代表拍长.*/};song2[]={C10,N1,D10,N1,E10,N1,F10,N1,G10,N1,A10,N1,B10,N1,C10,N2,D10,N2,E10,N2,F10,N2,G10,N2,A10,N2,B10,N2,C10,N4,D10,N4,E10,N4,F10,N4,G10,N4,A10,N4,B10,N4,C10,N8,D10,N8,E10,N8,F10,N8,G10,N8,A10,N8,B10,N8,C10,N16,D10,N16,E10,N16,F10,N16,G10,N16,A10,N16,B10,N16,C0,N1,D0,N1,E0,N1,F0,N1,G0,N1,A0,N1,B0,N1,C0,N2,D0,N2,E0,N2,F0,N2,G0,N2,A0,N2,B0,N2,C0,N4,D0,N4,E0,N4,F0,N4,G0,N4,A0,N4,B0,N4,C0,N8,D0,N8,E0,N8,F0,N8,G0,N8,A0,N8,B0,N8,C0,N16,D0,N16,E0,N16,F0,N16,G0,N16,A0,N16,B0,N16,C1,N1,D1,N1,E1,N1,F1,N1,G1,N1,A1,N1,B1,N1,C1,N2,D1,N2,E1,N2,F1,N2,G1,N2,A1,N2,B1,N2,C1,N4,D1,N4,E1,N4,F1,N4,G1,N4,A1,N4,B1,N4,C1,N8,D1,N8,E1,N8,F1,N8,G1,N8,A1,N8,B1,N8,C1,N16,D1,N16,E1,N16,F1,N16,G1,N16,A1,N16,B1,N16,C2,N1,D2,N1,E2,N1,F2,N1,G2,N1,A2,N1,B2,N1,C2,N2,D2,N2,E2,N2,F2,N2,G2,N2,A2,N2,B2,N2,C2,N4,D2,N4,E2,N4,F2,N4,G2,N4,A2,N4,B2,N4,C2,N8,D2,N8,E2,N8,F2,N8,G2,N8,A2,N8,B2,N8,C2,N16,D2,N16,E2,N16,F2,N16,G2,N16,A2,N16,B2,N16,END/*以上是⾳符测试代码,你可以通过系统发出的⾳调选择你需要的⾳符*//*注意:数组中的偶数元素代表⾳符奇数元素代表拍长.*/};song3[]= {C0,N8,C0,N8,G0,N8,G0,N8,A0,N8,A0,N8,G0,N4,F0,N8,F0,N8,E0,N8,E0,N8,D0,N8,D0,N8,C0,N4,G0,N8,G0,N8,F0,N4,E0,N8,E0,N8,D0,N4,G0,N8,G0,N8,F0,N8,F0,N8,E0,N8,E0,N8,D0,N4,C0,N8,E0,N8,G0,N4,A0,N8,C1,N8,G0,N4,F0,N8,F0,N8,E0,N8,E0,N4,D0,N8,D0,N8,C0,N4,C0,N8,C0,N8,G0,N8,G0,N8,A0,N8,A0,N8,G0,N4,F0,N8,F0,N8,E0,N8,E0,N8,D0,N8,D0,N8,C0,N4,G0,N8,G0,N8,F0,N4,E0,N8,E0,N8,D0,N4,G0,N8,G0,N8,F0,N8,F0,N8,E0,N8,E0,N8,D0,N4,C0,N8,E0,N8,G0,N4,A0,N8,C1,N8,G0,N4,F0,N8,F0,N8,E0,N8,E0,N4,D0,N8,D0,N8,C0,N4,END/*以上是曲⼦代码,你可以嵌⼊⾃⼰喜欢的歌曲代码*//*注意:数组中的偶数元素代表⾳符奇数元素代表拍长.*/};song4[]= {C10,N4,B0,N4,G0,N8,A0,N4,E0,N16,D0,N8,C0,N8,D0,N8,G0,N8,E0,N8,E0,N4,E0,N8,G0,N8,E0,N8,D0,N8,D0,N4,A0,N8,A0,N8,G0,N8,A0,N8,B0,N8,G0,N8,G0,N8,E0,N4,C10,N8,B0,N8,G0,N8,A0,N4,E0,N8,D0,N8,C0,N8,D0,N8,G0,N8,E0,N4,C0,N8,D0,N8,E0,N4,G0,N8,E0,N8,D0,N4,C0,N8,B10,N8,C0,N8,B10,N8,A10,N4,A0,N8,A0,N8,A0,N8,C1,N8,D1,N8, E1,N8,E1,N8,C1,N8,A0,N8,A0,N8,B0,N16,A0,N16,G0,N8,E0,N8,A0,N8,A0,N8,C1,N8,D1,N8,E1,N8,E1,N8,C1,N8,A0,N8,A0,N8,B0,N8,A0,N8,B0,N16,A0,N16,G0,N8,E0,N8,D1,N16,D1,N16,D1,N8, D1,N8,A0,N16,B0,N16,A0,N8,G0,N8,E0,N8,D1,N16,D1,N16,D1,N8, A0,N16,B0,N16,A0,N8,G0,N8,E0,N8,A0,N8,A0,N8,A0,N4,A0,N8,A0,N8,A0,N4,C10,N8,B0,N8,G0,N8,A0,N4,E0,N16,D0,N16,C0,N8, D0,N8,G0,N8,E0,N4,E0,N4,E0,N16,G0,N16,E0,N16,D0,N16,D0,N4,A0,N16,A0,N16,G0,N8,A0,N8,B0,N8,G0,N16,G0,N16,E0,N4,C10,N8,B0,N8,G0,N8,A0,N4,E0,N16,D0,N16,C0,N8,D0,N8,G0,N8,E0,N4,C0,N16,D0,N16,E0,N4,G0,N8,E0,N8,D0,N4,C0,N8,B10,N8,C0,N16,B10,N16,A10,N4,END};union {unsigned fre;unsigned char c[2];}tone;/*以下是播放程序代码*/void MusicPlay(int *song){int note=0,dur,control;clock_t goal;while(song[note]!=0){tone.fre=song[note];dur=song[note+1]; /*节拍*/if(kbhit())break;/*int kbhit()函数返回最近所敲的按键*/if(tone.fre){outportb(0x43,0xB6);/*函数void outportb(int port,char byte)将字节byte写⼊指定的输出端⼝port*/tone.fre=(unsigned)(1193180L/tone.fre);outportb(0x42,tone.c[0]);outportb(0x42,tone.c[1]);control=inportb(0x61);/*函数int inportb(int port)从指定的输⼊端⼝读⼊⼀个字节,并返回这个字节*/outportb(0x61,(control)|0x3);}goal=(clock_t)dur+clock();while(goal>clock());if(tone.fre)outportb(0x61,control);goal=(clock_t)0;note=note+2;}}/*以下是主函数其中包括异常处理*/void main(void){ int n;int graphdriver,graphmode;unsigned char *text[7] ;text[0]=" ";text[1]="start music........";text[2]="play the one music";text[3]="play the two music";text[4]="play the three music";text[5]="play the four music";text[6]="good_bye............";graphdriver=DETECT;graphmode=0;initgraph(&graphdriver,&graphmode,""); /*系统初始化 */cleardevice(); /* 清除屏幕 */settextjustify(LEFT_TEXT,CENTER_TEXT); /*设置字符排列⽅式*/printtext(text ,1, 1);getch();printtext(text ,2, 62);MusicPlay(song1);getch();printtext(text ,3,4);MusicPlay(song2);getch();printtext(text ,4, 58);MusicPlay(song3);getch();printtext(text ,5, 61);MusicPlay(song4);getch();printtext(text ,6, 63);getch();closegraph();}void printtext(unsigned char *temp[] , int i , int color){setcolor(color);settextstyle(TRIPLEX_FONT , HORIZ_DIR, 3);outtextxy(100, 40+i*50 , temp[i]); /* 显⽰字符串 temp[i]是具体的指针*/ }。
音乐播放器代码
音频播放器代码(1)<EMBED SRC="音乐文件地址">属性有:SRC="FILENAME" 设定音乐文件的路径AUTOSTART=TRUE/FALSE 是否要音乐文件传送完就自动播放,TRUE是要,FALSE是不要,默认为FALSELOOP=TRUE/FALSE 设定播放重复次数,LOOP=6表示重复6次,TRUE表示无限次播放,FALSE播放一次即停止。
STARTIME="分:秒" 设定乐曲的开始播放时间,如20秒后播放写为STARTIME=00:20VOLUME=0-100 设定音量的大小。
如果没设定的话,就用系统的音量。
WIDTH HEIGHT 设定控制面板的大小HIDDEN=TRUE 隐藏控制面板CONTROLS=CONSOLE/SMALLCONSOLE 设定控制面板样子例子:*************************************<html><head><title>播放音乐</title></head><body><EMBED SRC="midi.mid" autostart=true hidden=trueloop=true>作为背景音乐来播放。
</body></html>(2)wma格式音乐播放器代码自动播放代码<P align=center><EMBED name=Player34 pluginspage=/windows/mediapla yer/download/default.asp src=wma格式的歌曲地址width=200 height=50 type=application/x-mplayer2 showstatusbar="-1" AutoStart="-1" PlayCount="0" clicktoplay="-1"></P></EMBED>手动播放代码<P align=center><EMBED name=Player34 pluginspage=/windows/mediapla yer/download/default.asp src=wma格式的歌曲地址width=200 height=50 type=application/x-mplayer2 showstatusbar="-1" AutoStart="0" PlayCount="0" clicktoplay="-1"></P></EMBED>(3)mp3格式音乐播放器代码自动播放代码<P align=center><EMBED name=Player34pluginspage=/windows/mediapla yer/download/default.asp 格式的src=mp3歌曲地址width=200 height=50 type=application/x-mplayer2 showstatusbar="-1" AutoStart="-1" PlayCount="0" clicktoplay="-1"></P></EMBED>手动播放代码<P align=center><EMBED name=Player34 pluginspage=/windows/mediapla yer/download/default.asp src=mp3格式的歌曲地址width=200 height=50 type=application/x-mplayer2 showstatusbar="-1" AutoStart="0" PlayCount="0" clicktoplay="-1"></P></EMBED>(4)rm格式音乐播放器代码自动播放代码<P align=center><EMBED name=Player34 src=rm格式的歌曲地址width=200 height=50 type=application/octet-stream controls="StatusBar,ControlPanel" AutoStart="-1" numloop="0" loop="-1" clicktoplay="-1" nolabels="0" prefetch="0" shuffle="0" _extenty="847" _extentx="9657"></P></EMBED>手动播放代码<P align=center><EMBED name=Player34 src=rm格式的歌曲地址width=200 height=50 type=application/octet-stream controls="StatusBar,ControlPanel" AutoStart="0" numloop="0" loop="-1" clicktoplay="-1" nolabels="0" prefetch="0" shuffle="0" _extenty="847" _extentx="9657"></P></EMBED><html><head><meta name="generator" content="microsoft frontpage 6.0"> <meta name="progid" content="frontpage.editor.document"> <meta http-equiv="content-type" content="text/html; charset=gb2312"><title>插入音乐播放器</title></head>//只需要注意rows="*,21"这句就可以,21表示播放器占的高度为21个象素。
音乐播放器代码
以下为一款音乐播放器代码,长度(width="960")及高度(height="620")可调,自由切换百度随心听,贝瓦电台,豆瓣电台,音悦TV等多款音乐台。
代码一:<iframe id=TV name=TV frameborder=0 scrolling=no src=/yyzb width=960 height=550></iframe>代码二:<div><embed height="620" allownetworking="internal" width="960" allowscriptaccess="never" loop="-1" invokeurls="false" src="/yyzb" type="audio/mpeg" wmode="transparent"><br/></div>以下为已嵌入音乐播放器代码的网页代码,复制以下代码创建index.html文件上传空间即可播放音乐,友情链接可自己修改。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><link rel="shortcut icon" href="favicon.ico"><link rel="Bookmark" href="favicon.ico"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><meta name="keywords" content="音乐网"><meta name="description" content="音乐网"><title>音乐网_电视直播网</title><style type="text/css">BODY {SCROLLBAR-FACE-COLOR: #009ace; FONT-SIZE: 12px; SCROLLBAR-HIGHLIGHT-COLOR: #b8e9fa; SCROLLBAR-SHADOW-COLOR: #009aaa; COLOR: #a9c8e4; SCROLLBAR-ARROW-COLOR: #ffffff; SCROLLBAR-TRACK-COLOR: #cccccc; FONT-FAMIL Y: 宋体,Arial,Verdana ; BACKGROUND-COLOR: #8FC8D6; background-repeat: repeat-x}TD {FONT-SIZE: 12px; COLOR: #a9c8e4; LINE-HEIGHT: 140%}A:link {COLOR: #a9c8e4; TEXT-DECORA TION: none}A:visited {COLOR: #a9c8e4; TEXT-DECORA TION: none}A:active {COLOR: #a9c8e4; TEXT-DECORA TION: none}A:hover {COLOR: #00FF00; TEXT-DECORATION: underline}</style><META HTTP-EQUIV="pragma" CONTENT="no-cache"><META http-equiv="Cache-Control" content="no-cache"><META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate"></HEAD><BODY class=bg leftMargin=0 topMargin=0 marginheight="0" marginwidth="0" background="tv/bg.jpg"><TABLE cellSpacing=0 cellPadding=0 width=960 align=center border=0><TBODY><tr><td colspan="2" height=10></td></tr><tr><TD width=120 align=center ><a href=""><img border="0" src="/images/logo.gif" width="180" height="50" alt="电视直播网"></a></TD><TD width=840 align=right><script language="javascript" src="/vcp/getJScode/getJScode.asp?ReferenceID=684929&No=640x60"> </script></TD></TR><tr><td colspan="3" height=10></td></tr><tr><td colspan="2"><div><iframe id=TV name=TV frameborder=0 scrolling=no src=/yyzb width=960 height=550></iframe></div><TABLE cellSpacing=0 cellPadding=0 width=900 align=center border=0><TR><td align=center height=10></td></tr><TR><td align=center height=5></TD></TR><TR><td align=center><font color="#777777">©<br><div class="bottomx"><a><font color=slategray size=4>本站网址/zb 感谢转发微博、空间的朋友!谢谢你们!</a><div><p></p><font color="#777777"><a>友情连接: <a href="/c?s=a485395f&w=616248&c=17666&i=41910&l=0&e=&t=/cps/land/list/ 0" target="_blank"><font color=slategray size=2>蘑菇街</a> <ahref="/" target="_blank"><font color=slategray size=2>4399游戏</a> <a href="/rd/rd.aspx?e=181&adtype=1&unionid=liancaiping&subunionid=&other=&url=http%3A%2F%2Ftopic.moon %2Farticle%2Farticle_show%2F3816%3Ftype%3D0%26cn%3D13960%26other%3Dunionid%3Aliancaiping%7Cadtype%3A1%7Cadid%3A181%26adsiteid%3D10000007" target="_blank"><font color=slategray size=2>梦芭莎</a> <ahref="/?pid=mm_34029538_3439848_11149737" target="_blank"><font color=slategray size=2>爱淘宝</a> <ahref="/?pid=mm_34029538_3439848_11149737&tb_lm_id=l_sczl_sogou_cyg j" target="_blank"><font color=slategray size=2>一淘专享</a> <ahref="/go/act/taoke/ai_crown.php?pid=mm_34029538_3439848_1114973 7&unid=" target="_blank"><font color=slategraysize=2>TOP10店铺</a> <a href="/" target="_blank"><font color=slategray size=2>时光网址导航</a> <ahref="/?tracker_u=1787&uid=91520851657&website_id=521945"target="_blank"><font color=slategray size=2>一号店超市</a></a></font></div><div class="link">本站所有链接均收集自网络免费公开资源,非本站服务器资源,相关权责不由本站负责,若有侵权,请来信告知,本站会尽快删除!<br>Copyright © 2013 /tv/ Email:liancaiping@苏ICP备14004292号-1</font> <a href="/" target="_black" ><fontcolor=red size=2>返回</font></a> <a href="/" target="_black"><font color=red size=2>主页</a> 西部数码<ahref="/index.asp?ReferenceID=684929"target="_blank"><font color=slategray size=2>虚拟主机</a> </a><a href="/jtyy/" target="_blank"><font color=slategray size=2>家庭影院</a><b></TABLE></body></html>。
android音乐播放器---源代码
strings.xml<?xml version="1.0" encoding="utf-8"?><resources><string name="hello">Hello World, MainActivity!</string><string name="app_name">音乐播放器</string><string name="no_files">该目录为空</string><string name="to_top">[...]</string></resources>dimen.xml<?xml version="1.0" encoding="utf-8"?><resources><dimen name="music_title">20px</dimen><dimen name="music_list_title">20px</dimen><dimen name="widget_title_size">20px</dimen><dimen name="news_detail">16px</dimen><dimen name="text_size">18px</dimen><dimen name="news_item_title">19px</dimen><dimen name="text_size1">20px</dimen><dimen name="title">22px</dimen><dimen name="button_size">40px</dimen></resources>color.xml<?xml version="1.0" encoding="utf-8"?><resources><color name="white">#ffffff</color><color name="black">#000000</color><color name="widget_title">#b22222</color><color name="x_black">#292421</color><color name="blue">#3d59ab</color><color name="hui_black">#808a87</color></resources>setting.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:background="@drawable/bg"><LinearLayout android:layout_width="fill_parent"android:gravity="center" android:layout_height="wrap_content"android:background="@drawable/footer_bar"><TextView android:text="设定" android:id="@+id/setting"android:textSize="@dimen/music_list_title" android:layout_width="wrap_content"android:layout_height="wrap_content"></TextView></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="wrap_content" android:gravity="center_vertical"android:layout_height="wrap_content"><TextView android:text="播放模式" android:id="@+id/setting"android:textSize="@dimen/text_size" android:layout_width="fill_parent"android:layout_height="wrap_content"></TextView><RadioGroup android:id="@+id/RadioGroup"android:layout_width="wrap_content" android:layout_height="wrap_content"><RadioButton android:text="单曲循环" android:id="@+id/sigle_play"android:layout_width="wrap_content"android:layout_height="wrap_content"></RadioButton><RadioButton android:text="顺序播放" android:id="@+id/order_play"android:layout_width="wrap_content"android:layout_height="wrap_content"></RadioButton><RadioButton android:text="随机播放" android:id="@+id/random_play"android:checked="true" android:layout_width="wrap_content"android:layout_height="wrap_content"></RadioButton></RadioGroup></LinearLayout><LinearLayout android:orientation="horizontal"android:layout_width="wrap_content" android:gravity="center_vertical"android:layout_height="wrap_content"><TextView android:text="歌词显示" android:id="@+id/setting"android:textSize="@dimen/text_size" android:layout_width="wrap_content"android:layout_height="wrap_content" /><ToggleButton android:text="" android:id="@+id/ly_lrc"android:checked="false" android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout><TextView android:layout_width="fill_parent"android:layout_height="150px"></TextView><AbsoluteLayout android:background="@drawable/footer_bar"android:layout_width="fill_parent" android:layout_height="wrap_content"><ImageButton android:id="@+id/make" android:background="@drawable/share"android:layout_x="270px" android:layout_width="wrap_content"android:layout_height="wrap_content" /><ImageButton android:id="@+id/cancel" android:layout_x="5px"android:background="@drawable/back" android:layout_width="wrap_content"android:layout_height="wrap_content" /></AbsoluteLayout></LinearLayout>play_rack.xml<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="/apk/res/android"android:layout_width="fill_parent" android:layout_height="fill_parent"android:background="@drawable/bg1"><TextView android:layout_x="93px" android:layout_height="wrap_content"android:text="音乐播放器" android:layout_y="15px" android:id="@+id/title_music"android:textSize="@dimen/music_title"android:layout_width="wrap_content"></TextView><TextView android:layout_x="145px" android:layout_height="wrap_content"android:text="" android:layout_y="65px" android:id="@+id/current_music"android:textSize="18px" android:textColor="#C0FF3E"android:layout_width="wrap_content" android:textStyle="bold"></TextView><TextView android:layout_x="65px" android:layout_height="wrap_content"android:textSize="18px" android:textStyle="bold" android:text="正在播放:"android:layout_y="65px" android:textColor="#ff00ffff"android:layout_width="wrap_content"></TextView><LinearLayout android:layout_x="60px" android:layout_y="310px"android:gravity="center" android:layout_height="wrap_content"android:layout_width="wrap_content"><ImageButton android:layout_width="wrap_content"android:id="@+id/up_bt" android:layout_height="wrap_content"android:background="@drawable/up"></ImageButton><ImageButton android:layout_width="wrap_content"android:id="@+id/play_bt" android:layout_height="wrap_content"android:background="@drawable/play"></ImageButton><ImageButton android:layout_width="wrap_content"android:id="@+id/stop_bt" android:layout_height="wrap_content"android:background="@drawable/stop"></ImageButton><ImageButton android:layout_width="wrap_content"android:id="@+id/down_bt" android:layout_height="wrap_content"android:background="@drawable/down"></ImageButton><ImageButton android:layout_width="wrap_content"android:id="@+id/sound_bt" android:layout_height="wrap_content"android:background="@drawable/sound"></ImageButton></LinearLayout><SeekBar android:id="@+id/seekbar" android:layout_width="245px"android:layout_height="20px" android:layout_x="40px" android:layout_y="260px"android:progressDrawable="@drawable/seekbar_style"android:thumb="@drawable/thumb"android:paddingLeft="18px" android:paddingRight="15px"android:paddingTop="5px" android:paddingBottom="5px" android:progress="0"android:max="100" android:secondaryProgress="0"></SeekBar><TextView android:layout_x="60px" android:layout_height="wrap_content"android:text="00:00" android:layout_y="280px" android:id="@+id/current_time_text"android:layout_width="wrap_content"></TextView><TextView android:layout_x="230px" android:layout_height="wrap_content"android:text="00:00" android:layout_y="280px" android:id="@+id/end_Time_Text"android:layout_width="wrap_content"></TextView><ImageButton android:layout_width="wrap_content"android:layout_x="5px" android:layout_y="390px" android:id="@+id/list_bt"android:layout_height="wrap_content"android:background="@drawable/share"></ImageButton><ImageButton android:layout_x="270px"android:layout_height="wrap_content" android:layout_y="390px"android:id="@+id/back_bt" android:background="@drawable/back"android:layout_width="wrap_content"></ImageButton><LinearLayout android:orientation="horizontal"android:gravity="center" android:layout_y="370px"android:layout_height="wrap_content" android:layout_width="fill_parent"><TextView android:layout_height="wrap_content"android:textColor="#8deeee" android:id="@+id/lrcText"android:layout_width="wrap_content"></TextView></LinearLayout></AbsoluteLayout>play_list.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:background="@drawable/list_bg"><LinearLayout android:layout_width="fill_parent"android:gravity="center" android:layout_height="wrap_content"android:background="@drawable/footer_bar"><TextView android:text="歌曲列表" android:id="@+id/music_list"android:textSize="@dimen/music_list_title" android:textStyle="bold"android:layout_width="wrap_content"android:layout_height="wrap_content"></TextView></LinearLayout><ListView android:id="@+id/show_play_list"android:layout_width="fill_parent" android:layout_height="337px"></ListView><LinearLayout android:layout_width="fill_parent"android:gravity="right" android:layout_height="wrap_content"android:background="@drawable/footer_bar"><ImageButton android:id="@+id/back" android:background="@drawable/back"android:layout_width="wrap_content"android:layout_height="wrap_content"></ImageButton></LinearLayout></LinearLayout>menu.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:background="@drawable/list_bg"><LinearLayout android:layout_width="fill_parent"android:gravity="center" android:layout_height="wrap_content"android:background="@drawable/footer_bar"><TextView android:text="选项" android:id="@+id/select_item"android:textSize="@dimen/music_list_title" android:textStyle="bold"android:layout_width="wrap_content"android:layout_height="wrap_content"></TextView></LinearLayout><ListView android:id="@+id/menu" android:layout_width="wrap_content"android:background="@drawable/list_item_bg"android:layout_height="wrap_content"></ListView><TextView android:layout_width="wrap_content"android:layout_height="50px"></TextView><LinearLayout android:layout_width="fill_parent" android:gravity="right"android:layout_height="wrap_content" android:background="@drawable/footer_bar"><ImageButton android:id="@+id/back"android:background="@drawable/back"android:layout_width="wrap_content"android:layout_height="wrap_content"></ImageButton></LinearLayout></LinearLayout>file_row.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="horizontal" android:layout_width="fill_parent" android:background="@drawable/list_item_xml"android:layout_height="wrap_content" android:gravity="center_vertical"><ImageView android:id="@+id/image_Icon" android:layout_width="30px"android:layout_height="30px" android:background="@drawable/icon"></ImageView><TextView android:layout_width="10px"android:layout_height="wrap_content" /><TextView android:text="" android:id="@+id/text"android:layout_width="wrap_content" android:layout_height="wrap_content"android:textColor="@color/x_black"android:textSize="@dimen/text_size"></TextView></LinearLayout>directory_list.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"android:orientation="vertical" android:layout_width="fill_parent"android:layout_height="fill_parent" android:background="@drawable/list_bg"><LinearLayout android:layout_width="fill_parent"android:gravity="center" android:layout_height="wrap_content"android:background="@drawable/footer_bar"><TextView android:text="SD卡" android:id="@+id/store_card" android:textStyle="bold"android:layout_width="wrap_content" android:layout_height="wrap_content"android:textSize="@dimen/music_list_title"></TextView></LinearLayout><ListView android:id="@id/android:list" android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextView android:layout_width="10px"android:layout_height="wrap_content" /><TextView android:id="@id/android:empty" android:layout_width="wrap_content"android:layout_height="wrap_content" android:text="@string/no_files" /></LinearLayout>StringHelper.javapackage com.Rain.music.util;import java.util.ArrayList;import java.util.List;public class StringHelper {public static List<String> spiltString(String str) {List<String> music_List = new ArrayList<String>();String[] musics = str.split(";");for (int i = 0; i < musics.length; i++) {music_List.add(musics[i]);}return music_List;}public static String toStringAll(List<String> music_List) {StringBuffer buffer = new StringBuffer();if (music_List.size() > 0) {for (int i = 0; i < music_List.size(); i++) {buffer.append(music_List.get(i));if (i < music_List.size() - 1)buffer.append(";");}return buffer.toString();}}MusicHelp.javapackage com.Rain.music.util;import android.media.MediaPlayer;import android.os.Handler;public class MusicHelp {private static MediaPlayer player = null;private static Handler objHandler = null; public static MediaPlayer getMediaPlayer() { if (player == null)player = new MediaPlayer();return player;}public static Handler getHandler(){if (objHandler == null)objHandler = new Handler(); return objHandler;}}MusicAdapter.javapackage com.Rain.music.util;import java.io.File;import java.util.List;import com.Rain.music.activity.R;import com.Rain.music.dao.DBProvider; import android.content.ContentResolver; import android.content.Context;import android.database.Cursor;import android.graphics.Bitmap;import android.graphics.BitmapFactory; import .Uri;import youtInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;public class MusicAdapter extends BaseAdapter { private Bitmap down_Icon;public Bitmap getDown_Icon() {return down_Icon;}public void setDown_Icon(Bitmap downIcon) {down_Icon = downIcon;}public Bitmap getUp_Icon() {return up_Icon;}public void setUp_Icon(Bitmap upIcon) {up_Icon = upIcon;}public Bitmap getSuspend_Icon() {return suspend_Icon;}public void setSuspend_Icon(Bitmap suspendIcon) {suspend_Icon = suspendIcon;}public Bitmap getPlay_Icon() {return play_Icon;}public void setPlay_Icon(Bitmap playIcon) {play_Icon = playIcon;}LayoutInflater inflater;private Bitmap up_Icon;private Bitmap suspend_Icon;private Bitmap play_Icon;private Bitmap music_File;private Bitmap father_File;// 父目录private Bitmap folder_File;// 目录//private Bitmap docm_File;private List<String> list;Context context;public MusicAdapter(Context context, List<String> list) { this.list = list;this.context = context;inflater = LayoutInflater.from(context);//位图工厂play_Icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.play);up_Icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.up);suspend_Icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.suspend);down_Icon = BitmapFactory.decodeResource(context.getResources(),R.drawable.down);music_File = BitmapFactory.decodeResource(context.getResources(),R.drawable.music_file);father_File = BitmapFactory.decodeResource(context.getResources(),R.drawable.father_file);folder_File = BitmapFactory.decodeResource(context.getResources(),R.drawable.folder_file);/*docm_File = BitmapFactory.decodeResource(context.getResources(),R.drawable.doc_file);*/}@Overridepublic int getCount() {return list.size();}@Overridepublic Object getItem(int position) {return list.get(position);}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;if (convertView == null) {holder = new ViewHolder();convertView = inflater.inflate(yout.file_row, null);holder.text = (TextView) convertView.findViewById(R.id.text);holder.icon = (ImageView) convertView.findViewById(R.id.image_Icon);convertView.setTag(holder);} else {holder = (ViewHolder) convertView.getTag();}//holder.text.setTextColor(Color.WHITE);//holder.text.setTextSize(22);if (list.get(position).toString().equals("[...]")) {// 如果是父目录holder.text.setText("[Back]");holder.icon.setImageBitmap(father_File);}if (list.get(position).toString().equals("/sdcard")|| list.get(position).toString().equals("/system")) { holder.text.setText(list.get(position));holder.icon.setImageBitmap(folder_File);}else {String path = null;if (!"[...]".equals(list.get(position).toString())) {path = query(list.get(position).toString());}if (path != null) {File f = new File(path);holder.text.setText(list.get(position));if (f.isDirectory()) {holder.icon.setImageBitmap(folder_File);}else {if (path.indexOf(".mp3") != -1) {holder.text.setText(list.get(position));holder.icon.setImageBitmap(music_File);}}}else {if ((list.get(position).indexOf(".mp3") != -1)){holder.text.setText(list.get(position));holder.icon.setImageBitmap(music_File);}else {holder.text.setText(list.get(position));holder.icon.setImageBitmap(folder_File);if (list.get(position).equals("[...]")) {holder.icon.setImageBitmap(father_File);}}}}return convertView;}public String query(String fileName) {// 查询歌曲路径ContentResolver cr = context.getContentResolver();Uri uri = DBProvider.CONTENT_URI;String[] projection = { "path" };String selection = "fileName=?";String[] selectionArgs = { fileName };Cursor c = cr.query(uri, projection, selection, selectionArgs, null);if (c.moveToFirst()) {String path = c.getString(0);return path;}return null;}private class ViewHolder {private TextView text;private ImageView icon;}}LrcShow.javapackage com.Rain.music.util;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import android.content.Context;import android.content.SharedPreferences;public class LrcShow {@SuppressWarnings("static-access")public static void showLrc(String musicName, Context context) { BufferedReader file;String s = null;StringBuffer lrc_time = new StringBuffer();StringBuffer lrc_word = new StringBuffer();try {SharedPreferences sp = context.getSharedPreferences("LRC_SHOW",context.MODE_WORLD_WRITEABLE); SharedPreferences.Editor editor = sp.edit();file = new BufferedReader(new FileReader(new File("/sdcard/"+ musicName + ".lrc")));while ((s = file.readLine()) != null) {if (s.split("]").length == 2) {lrc_time.append(s.split("]")[0] + ";");lrc_word.append(s.split("]")[1] + ";");}}editor.putString("MUSIC_TITLE", musicName);editor.putString("LRC_TIME", lrc_time.toString());editor.putString("LRC_WORD", lrc_word.toString());mit();}catch (IOException e) {e.printStackTrace();SharedPreferences sp = context.getSharedPreferences("LRC_SHOW",context.MODE_WORLD_WRITEABLE); SharedPreferences.Editor editor = sp.edit();editor.putString("MUSIC_TITLE", musicName);editor.putString("LRC_TIME", null);editor.putString("LRC_WORD", null);mit();}}}FileColumn.javapackage com.Rain.music.util;public class FileColumn {//音乐属性类//表明public static final String TABLE="File_Table";//列名public static final String ID="fileId";public static final String NAME="fileName";public static final String PA TH="path";public static final String TYPE="type";public static final String SORT="sortPId";public static final int ID_COLUMN = 0;public static final int NAME_COLUMN = 1;public static final int PA TH_COLUMN = 2;public static final int TYPE_COLUMN = 3;public static final int SORT_COlUMN = 4;public static String[] getColumArray(){return new String[]{ID,NAME,PATH,TYPE,SORT};}}SystemProvider.javapackage com.Rain.music.dao;import android.content.ContentResolver;import android.content.Context;import android.database.Cursor;import android.os.RemoteException;import android.provider.MediaStore;public class SystemProvider {private Context context;private Cursor cursor;public SystemProvider(Context context) {this.context = context;}public Cursor allSongs() {if (cursor != null)return cursor;ContentResolver resolver = context.getContentResolver();cursor = resolver.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);return cursor;}public String getArtist() {return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));}public String getTitle() {String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));/*try {title=EncodingUtils.getString(title.getBytes(), "UTF-8");} catch (Exception e) {e.printStackTrace();}*/return title;}public String getAlbum() throws RemoteException {// 读取正在播放歌曲的专辑return cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));}/*public int getDuration() throws RemoteException {// 获得当前歌曲的时长return player.getDuration();}public int getTime() throws RemoteException {// 获得当前的媒体时间return player.getCurrentPosition();}*/}DBProvider.javapackage com.Rain.music.dao;import com.Rain.music.util.FileColumn;import android.content.ContentProvider;import android.content.ContentValues;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import .Uri;import android.util.Log;public class DBProvider extends ContentProvider {private DBHelper dbOpenHelper;public static final String AUTHORITY = "MUSIC";public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + FileColumn.TABLE);@Overridepublic int delete(Uri arg0, String arg1, String[] arg2) {SQLiteDatabase db = dbOpenHelper.getWritableDatabase();try {db.delete(FileColumn.TABLE, arg1, arg2);Log.i("info", "delete");} catch (Exception ex) {ex.printStackTrace();Log.e("error", "delete");}return 1;}@Overridepublic String getType(Uri uri) {return null;}@Overridepublic Uri insert(Uri uri, ContentValues values) {SQLiteDatabase db = dbOpenHelper.getWritableDatabase();long count = 0;try {count = db.insert(FileColumn.TABLE, null, values);} catch (Exception ex) {ex.printStackTrace();Log.e("error", "insert");}if (count > 0)return uri;elsereturn null;}@Overridepublic boolean onCreate() {dbOpenHelper = new DBHelper(getContext());return true;}@Overridepublic Cursor query(Uri uri, String[] projection, String selection,String[] selectionArgs, String sortOrder) {SQLiteDatabase db = dbOpenHelper.getWritableDatabase();// 依次参数为:表明,查询字段,where语句,占位符替换,group by(分组),having(分组条件),order by(排序)Cursor cur = db.query(FileColumn.TABLE, projection, selection,selectionArgs, null, null, sortOrder);return cur;}@Overridepublic int update(Uri uri, ContentValues values, String selection,String[] selectionArgs) {SQLiteDatabase db = dbOpenHelper.getWritableDatabase();int i = 0;try {i = db.update(FileColumn.TABLE, values, selection, null);return i;} catch (Exception ex) {Log.e("error", "update");}return 0;}}DBHelper.javapackage com.Rain.music.dao;import com.Rain.music.util.FileColumn;。
音乐播放器源代码
P align=center><TABLE borderColor=#4f3256 align=centerbackground=/zh_cn/home4u/sucai/gifanimation/line/0022.gifborder=1><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"> <P align=center><EMBED src=width=369 height=39type=audio/mpeg loop="-1" autostart="ture"volume="0"></P></TD></TR></TBODY></TABLE></P>autostart="true"中true或1表示自动播放,false或0表示手动播放loop="true" 中的true或1表示重复播放,false或0表示只播放一次width= height= 中的数字分别表示播放器的宽度和高度=0表示隐藏播放器EnableContextMenu="0" 禁右键ShowStatusBar="1" (带显示文件播放信息)=======================================================隐藏(hidden=true)播放器(不循环)<EMBED src=音乐网址hidden=true type=audio/x-ms-wma AUTOSTART="1">-----------------------------------------------------------隐藏(hidden=true)播放器(循环)<EMBED src=音乐网址hidden=true type=audio/mpeg AUTOSTART="1" loop="-1"> ---------------------------------------------------------------黑色[style="FILTER: xray()"]循环[loop="-1"]播放器<EMBED style="FILTER: xray()" src=音乐网址width=360 height=30type=audio/mpeg volume="0" autostart="true" loop="-1">--------------------------------------------------------------------------------浅兰色循环(loop="-1")播放器<EMBED src=音乐网址width=300 height=45 type=audio/mpeg loop="-1"autostart="true" volume="0">--------------------------------------------------------------------------掩饰自动播放器<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)gray(); WIDTH: 200px; HEIGHT: 83px"><TBODY><TR><TD><EMBED src=音乐网址width=200 height=40 type=audio/mpeg panel="0" autostart="true" loop="true"></TD></TR></TBODY></TABLE>-------------------------------------连播放时选择曲目的播放器<EMBEDpluginspage=/windows/mediaplayer/download/default.as p width=400 height=172 type=application/x-mplay er2 FileName="音乐网址" SHOWCONTROLS="1" SHOWSTATUSBAR="1" SHOWDISPLAY="1" SHOWGOTOBAR="1" AUTOSTART="true" PlayCount="1">----------------------------------------------------------------------------------------------显示曲名的黑色带彩自动播放器<EMBED style="FILTER: invert()" src=音乐网址width=320 height=45type=audio/x-ms-wma ShowStatusBar="1" loop="true" autostart="true">-------------------------------------------------------------------------显示曲名的灰白色面板<EMBED style="FILTER: Gray()" src="链接地址" width=300 height=69type=application/x-mplayer2 loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1" autostart="1"></EMBED>------------------------------------------灰白面板<embed style="FILTER: Gray()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>---------------------------------------------------------------(带显示文件播放信息)<EMBED src="链接地址" width=300 height=69 type=application/x-mplay er2loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1"autostart="1"></EMBED>-----------------------------------------------黑色带彩棕色面板<EMBED style="FILTER: invert()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>---------------------------------------------------------------------浅紫播放器<TABLE borderColor=#4F3256background=/DownloadImg/2010/09/0718/5119955_3.jpg border=1><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg loop="-1" autostart="false" volume="0"></P></TD></TR></TBODY></TABLE>----------------------------------------------------------------------------------------------粉色<TABLE borderColor=navybackground=/UploadFile/2005-9/200592522275884778.jpg border=0><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=300 height=45 type=audio/mpeg loop="-1" autostart="0" volume="0"></P></TD></TR></TBODY></TABLE>------------------------------------------------------------------------------------黄色闪光<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=navybackground=/s-helpSite/domName/nxm/20041114123131568.gi f border=0><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=400 height=35 type=audio/mpeg loop="-1" autostart="0" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>--------------------------------------------------------------------------------蓝色闪光<TABLE borderColor=#dee4fe cellSpacing=3 cellPadding=0background=/UploadFile/2004-12/2004123023101352.gif border=2><TBODY><TR><TD><TABLE align=center border=0><TBODY><TR><TD style="FILTER: alpha(opacity=60,style=3)"><P align=center><EMBED style="FILTER: Gray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>-------------------------------------------------------------------------花边黑色<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=#000000 align=center border=1><TBODY><TR><TD><P align=center><EMBED style="FILTER: Xray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>-----------------------------------------------------------------------------------------------------粉色花边<TABLE style="BORDER-RIGHT: #ff69b4 3px dotted; BORDER-TOP: #ff69b4 3px dotted; BORDER-LEFT: #ff69b4 3px dotted; BORDER-BOTTOM: #ff69b4 3px dotted" cellSpacing=0 cellPadding=0 align=center bgColor=white><TBODY><TR><TD><TABLE borderColor=#ff69b4 align=center bgColor=#ffccf5 border=2><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"><P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg volume="0" autostart="false" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>-------------------------------------------------------------------------------------------禁右键播放器<EMBED style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid" src=音乐网址width=200 height=40 type=audio/x-mplayer2 console="video" showstatusbar="0" EnableContextMenu="0" volume="0" autostart="0" loop="-1">---------------------------------------------------------------------------------上下移动<MARQUEE style="LEFT: 230px; ; TOP: 300px" scrollAmount=1 scrollDelay=200 direction=up behavior=alternate width=300 height=400><br><MARQUEE scrollAmount=1 scrollDelay=100 behavior=alternate><br><TABLE style="FILTER: progid:DXImageTransform.Microsoft.Shadow(color:#7ec0ee ,direction:145,strengt h:20)" cellSpacing=0 cellPadding=0 border=1><br><TBODY><br><TR><br><TD><EMBED style="FILTER: gray()" src=音乐网址width=200 height=20type=audio/mpeg showstatusbar="1" volume="0" loop="-1" autostart="1"></TD></TR></TBODY></TABLE></MARQUEE></MARQUEE>-------------------------------------------------------------------(显示文件标签信息)蓝色<DIV><EMBED src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true" transparentatstart="true"></EMBED></div>--------------------------------------------------(显示文件标签信息)灰白<DIV><EMBED style="FILTER: Gray()" src="链接地址" loop="-1" width=300height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true"autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>----------------------------------------------------(显示文件标签信息)黑彩<DIV><EMBED style="FILTER: invert()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true"showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true"autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>-----------------------------------------------------------(显示文件标签信息)黑<DIV><EMBED style="FILTER: xray()" src="链接地址" loop="-1" width=300height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true"autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>===================================================连放<EMBED style="FILTER: Gray()" src=音乐网址width=500 height=35type=audio/x-ms-wma controls="StatusBar,TACCtrl,ControlPanel" border="0" autostart="1" playcount="0" showtracker="1" volume="0"></EMBED>=========================================================图片播放器!<TABLE style="FILTER: alpha(opacity=100 Style=0 FinishOpacity=100)" borderColor=#000000 height=249 cellSpacing=0 cellPadding=0 width=314 background=/DownloadImg/2010/09/0718/5119955_4.gif border=0><TBODY><TR><TD width=314 height=180 cellpadding="0" cellspacing="0"></TD></TR><TR><TD align=left><P align=center><EMBED style="FILTER: alpha(opacity=100 Style=3 FinishOpacity=0)black(); style: " src=音乐网址width=310 height=28 type=video/x-ms-asf loop="-1" autostart="1" volume="0"></P></TD></TR></TBODY></TABLE>=================================================以上效果分见如下::为免各效果同时播放,以下autostart=0autostart="true"中true或1表示自动播放,false或0表示手动播放loop="true" 中的true或1表示重复播放,false或0表示只播放一次width= height= 中的数字分别表示播放器的宽度和高度=0表示隐藏播放器EnableContextMenu="0" 禁右键ShowStatusBar="1" (带显示文件播放信息)=======================================================隐藏(hidden=true)播放器(不循环)src="/LIU/all_about_you.wma" hidden="true"type="audio/x-ms-wma" allowscriptaccess="never" autostart="0">-----------------------------------------------------------隐藏(hidden=true)播放器(循环)src="/LIU/all_about_you.wma" hidden="true"type="audio/mpeg" allowscriptaccess="never" autostart="0" loop="-1">---------------------------------------------------------------黑色[style="FILTER: xray()"]循环[loop="-1"]播放器style="FILTER: xray()" src="/LIU/all_about_you.wma" width="360" height="30" type="audio/mpeg" allowscriptaccess="never"volume="0" autostart="0" loop="-1">--------------------------------------------------------------------------------浅兰色循环(loop="-1")播放器src="/LIU/all_about_you.wma" width="300" heigh t="45" type="audio/mpeg" allowscriptaccess="never" loop="-1" autostart="0"volume="0">--------------------------------------------------------------------------掩饰自动播放器src="/LIU/all_about_you.wma"width="200" height="40" type="audio/mpeg"allowscriptaccess="never" panel="0" autostart="0"loop="true">-------------------------------------连播放时选择曲目的播放器pluginspage="/windows/mediaplayer/download/default.a sp" width="400" height="172" type="application/x-mplayer2"allowscriptaccess="never"filename="/LIU/all_about_you.wma" showcontrols="1" showstatusbar="1" showdisplay="1" showgotobar="1" autostart="0"playcount="1">----------------------------------------------------------------------------------------------显示曲名的黑色带彩自动播放器style="FILTER: invert()" src="/LIU/all_about_you.wma" width="320" height="45" type="audio/x-ms-wma" allowscriptaccess="never" showstatusbar="1" loop="0" autostart="0">-------------------------------------------------------------------------显示曲名的灰白色面板style="FILTER: Gray()" src="/LIU/all_about_you.wma" width="300" height="69" type="application/x-mplay er2" allowscriptaccess="never" loop="-1" showcontrols="1" showdisplay="0" showstatusbar="1" autostart="0"> ------------------------------------------灰白面板style="FILTER: Gray()" src="/LIU/all_about_you.wma" width="300" height="45" type="audio/x-ms-wma" allowscriptaccess="never"loop="-1" autostart="0">---------------------------------------------------------------(带显示文件播放信息)src="/LIU/all_about_you.wma" width="300" height="69" type="application/x-mplay er2" allowscriptaccess="never" loop="-1"showcontrols="1" showdisplay="0" showstatusbar="1" autostart="0">-----------------------------------------------黑色带彩棕色面板style="FILTER: invert()" src="/LIU/all_about_you.wma" width="300" height="45" type="audio/x-ms-wma" allowscriptaccess="never"loop="-1" autostart="0"><CENTER><TABLE style="BORDER-RIGHT: #f1dda1 2px ridge; BORDER-TOP: #bdb76b 2px ridge; BORDER-LEFT: #f1dda1 2px ridge; BORDER-BOTTOM: #bdb76b 2px ridge; BACKGROUND-COLOR: white" borderColor=#ffffff cellPadding=0width=300 align=centerbackground=/fileuploaddir/4B2686448.4.gifborder=0><TBODY><TR><TD width=300 height=20 cellPadding="0"cellSpacing="0"><TABLE align=center border=0><TBODY><TR><TDstyle="FILTER: alpha(opacity=60,style=3)"><P align=center><EMBED style="FILTER: invert(); WIDTH: 290px; HEIGHT: 28px" src=/Q/.Wma type=audio/x-ms-wma autostart="true"loop="-1"volume="0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></CENTER一、音乐播放器源代码(神采飞扬版)P align=center><TABLE borderColor=#4f3256 align=center background=http://tech.china.com/zh_cn/home4u/sucai/gifanimation/line/0022.gif border=1><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"><P align=center><EMBED src=width=369 height=39type=audio/mpeg loop="-1" autostart="ture" volume="0"></P></TD></TR> </TBODY></TABLE></P>二、具体操作步骤1、在“BLOG发表文章”网页里,也即是写文章的网页里,写好文字后,选中文字上方的“查看HTML源代码”项(选项前的方框内出现√则为选中),这时我们看见原来的文字成了汉字、英文字母和一些诸如<、/、=等符号组成的乱码。
视频音乐播放器代码大全
视频音乐播放器代码大全(珍藏限量版)autostart="true"中true或1表示自动播放,false或0表示手动播放loop="true" 中的true或1表示重复播放,false或0表示只播放一次width= height= 中的数字分别表示播放器的宽度和高度=0表示隐藏播放器EnableContextMenu="0" 禁右键ShowStatusBar="1" (带显示文件播放信息)1隐藏播放器(不循环)代码:<EMBED src=音乐网址hidden=true type=audio/x-ms-wmaAUTOSTART="1">2.隐藏播放器(循环播放)代码:<EMBED src=音乐网址hidden=true type=audio/mpegAUTOSTART="1" loop="-1">3.黑色皮肤播放器代码:<EMBED style="FILTER: xray()" src=音乐网址width=360 height=30 type=audio/mpeg volume="0" autostart="true" loop="-1">4.淡蓝色播放器代码:<EMBED src=播放地址 width=300 height=45 type=audio/mpegloop="-1" autostart="1" volume="0">5.迷幻播放器代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)gray(); WIDTH:400px; HEIGHT: 83px"><TBODY><TR><TD><EMBED src=播放地址 width=400 height=40 type=audio/mpeg panel="0" autostart="0" loop="true"></TD></TR></TBODY></TABLE>6.带菜单的播放器代码:<EMBEDpluginspage=/windows/mediaplayer/downlo ad/default.asp width=400 height=172 type=application/x-mplayer2 FileName="音乐网址" SHOWCONTROLS="1" SHOWSTATUSBAR="1" SHOWDISPLAY="1" SHOWGOTOBAR="1"AUTOSTART="true" PlayCount="1">7.深黄色带菜单播放器代码:<EMBED style="FILTER: invert()" src=音乐网址width=320 height=45 type=audio/x-ms-wma ShowStatusBar="1" loop="true"autostart="true">8.灰色播放器代码:<EMBED style="FILTER: Gray()" src="链接地址" width=300 height=69 type=application/x-mplayer2 loop="-1" showcontrols="1"ShowDisplay="0" ShowStatusBar="1" autostart="1"></EMBED>9.灰白色播放器代码:<embed style="FILTER: Gray()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>10.带菜单的蓝色播放器代码:<EMBED src="链接地址" width=300 height=69type=application/x-mplayer2 loop="-1" showcontrols="1"ShowDisplay="0" ShowStatusBar="1" autostart="1"></EMBED>11.棕色播放器代码:<EMBED style="FILTER: invert()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>12.带边框背景的播放器代码:<TABLE borderColor=#4F3256 background=背景图片地址 border=1><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"> <P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg loop="-1" autostart="false" volume="0"></P></TD></TR></TBODY></TABLE>13.带背景图片的播放器代码:<TABLE borderColor=navy background=图片地址border=0><TBODY><TR><TD style="FILTER: alpha(opacity=80,style=3)"> <P align=center><EMBED src=音乐网址width=300 height=45 type=audio/mpeg loop="-1" autostart="0" volume="0"></P></TD></TR></TBODY></TABLE>12 13综合属性分析background=图片地址可以更换图片地址来实现改变播放器背景14.黄色闪光播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=navybackground=/s-helpSite/domName/nxm/20041114123131568.gif border=0><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"> <P align=center><EMBED src=音乐网址width=400 height=35 type=audio/mpeg loop="-1" autostart="0" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>15.蓝色闪光播放器代码:<TABLE borderColor=#dee4fe cellSpacing=3 cellPadding=0 background=/UploadFile/2004-12/2004123023 101352.gif border=2><TBODY><TR><TD><TABLE align=centerborder=0><TBODY><TR><TD style="FILTER: alpha(opacity=60,style=3)"> <P align=center><EMBED style="FILTER: Gray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false"loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>16.带花边的播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=#000000 align=center border=1><TBODY><TR><TD><P align=center><EMBED style="FILTER: Xray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false"loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>17.粉色花边播放器代码:<TABLE style="BORDER-RIGHT: #ff69b4 3px dotted; BORDER-TOP: #ff69b4 3px dotted; BORDER-LEFT: #ff69b4 3px dotted;BORDER-BOTTOM: #ff69b4 3px dotted" cellSpacing=0cellPadding=0 align=center bgColor=white><TBODY><TR><TD><TABLE borderColor=#ff69b4 align=center bgColor=#ffccf5border=2><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"> <P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg volume="0" autostart="false" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>18.显示文件标签灰色播放器代码:<DIV><EMBED style="FILTER: Gray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true"showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>19显示文件标签棕色播放器代码:<DIV><EMBED style="FILTER: invert()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true"showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>20.显示文件标签黑色播放器代码:<DIV><EMBED style="FILTER: xray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true"showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>21.连放播放器代码:<EMBED style="FILTER: Gray()" src=音乐网址width=500 height=35 type=audio/x-ms-wma controls="StatusBar,TACCtrl,ControlPanel"border="0" autostart="1" playcount="0" showtracker="1"volume="0"></EMBED>22.彩色播放器代码:<TABLE style="FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: 00CCFF; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana; FONT-VARIANT: normal" cellSpacing=0 cellPadding=0 width=140border=0><TBODY><TR><TD style="BACKGROUND-COLOR:00CCFF"><EMBED style="FILTER: invert alpha(opacity=50) WIDTH: 140px; HEIGHT: 45px" src=音乐链接地址type=video/x-ms-asf autostart="FALSE" loop="-1"volume="0"></EMBED></TD></TR></TBODY></TABLE>本代码属性分析BACKGROUND-COLOR: 00CCFF播放器颜色代码可以更换以变换播放器颜色23.透明播放器代码代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)xray(); WIDTH:200px; HEIGHT: 40px"><TBODY><TR><TD><EMBED style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid" src=音乐链接地址width=200 height=30 type=audio/x-mplayer2 loop="-1" autostart="0" volume="0"EnableContextMenu="0" showstatusbar="0"console="video"></TD></TR></TBODY></TABLE><p><span style="font-family:楷体;font-size:small;color:#156200;"><strong> <a href="">茶艺茗国际商城</a></strong>直供<strong><a href="/Product.aspx?BigId=1&SmallId=7">正品铁观音</a></strong>、西湖龙井、<strong><a href="/Product.aspx?BigId=3&SmallId=15">云南普洱</a></strong>、红茶等中国各大<strong><a href="/61/">品牌茗茶</a></strong>,及其它<strong><a href="/Product.aspx?BigId=5&SmallId=0">保健茶</a></strong>、茶食品、茶具等相关产品。
C WIN32音乐播放器源代码(主要代码).cpp
BOOL Main_Dialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
//*******************************************************************************************************************
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
M_MUSIC(hwnd,TEXT("close"),numberup);
--number;
M_UPDOWN(hwnd);
M_MUSIC(hwnd,TEXT("play"),number);
}
break;
case IDC_PAUSE:
{
//*******************************************************************************************************************// 其它情况
default:
break;
}
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
音乐播放器代码大全
音乐播放器代码大全单曲音乐代码大全:autostart="true"中true或1表示自动播放,false或0表示手动播放loop="true" 中的true或1表示重复播放,false或0表示只播放一次width= height= 中的数字分别表示播放器的宽度和高度 =0表示隐藏播放器EnableContextMenu="0" 禁右键ShowStatusBar="1" (带显示文件播放信息)1隐藏播放器(不循环)代码:<EMBED src=音乐网址hidden=true type=audio/x-ms-wma AUTOSTART="1">2.隐藏播放器(循环播放)代码:<EMBED src=音乐网址hidden=true type=audio/mpeg AUTOSTART="1" loop="-1">3.黑色皮肤播放器代码:<EMBED style="FILTER: xray()" src=音乐网址width=360 height=30 type=audio/mpeg volume="0" autostart="true" loop="-1">4.淡蓝色播放器代码:<EMBED src=播放地址width=300 height=45 type=audio/mpeg loop="-1" autostart="1" volume="0">5.迷幻播放器代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)gray(); WIDTH: 400px; HEIGHT: 83px"><TBODY><TR><TD><EMBED src=播放地址width=400 height=40 type=audio/mpeg panel="0" autostart="0" loop="true"> </TD></TR></TBODY></TABLE>6.带菜单的播放器代码:<EMBED pluginspage= width=400 height=172 type=application/x-mplayer2 FileName="音乐网址" SHOWCONTROLS="1" SHOWSTATUSBAR="1" SHOWDISPLAY="1" SHOWGOTOBAR="1" AUTOSTART="true" PlayCount="1">7.深黄色带菜单播放器代码:<EMBED style="FILTER: invert()" src=音乐网址width=320 height=45 type=audio/x-ms-wma ShowStatusBar="1" loop="true" autostart="true">8.灰色播放器代码:<EMBED style="FILTER: Gray()" src="链接地址" width=300 height=69 type=application/x-mplayer2 loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1" autostart="1"></EMBED>9.灰白色播放器代码:<embed style="FILTER: Gray()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>10.带菜单的蓝色播放器代码:<EMBED src="链接地址" width=300 height=69 type=application/x-mplayer2 loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1" autostart="1"></EMBED>11.棕色播放器代码:<EMBED style="FILTER: invert()" src=链接地址width=300 height=45 loop="-1" autostart="true"></EMBED>12.带边框背景的播放器代码:<TABLE borderColor=#4F3256 background=背景图片地址border=1><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg loop="-1" autostart="false" volume="0"></P></TD></TR></TBODY></TABLE>13.带背景图片的播放器代码:<TABLE borderColor=navy background=图片地址border=0> <TBODY><TR><TD style="FILTER: alpha(opacity=80,style=3)"><P align=center><EMBED src=音乐网址width=300 height=45 type=audio/mpeg loop="-1" autostart="0" volume="0"></P></TD></TR></TBODY></TABLE>12 13综合属性分析background=图片地址可以更换图片地址来实现改变播放器背景14.黄色闪光播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=navy background= border=0><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=400 height=35 type=audio/mpeg loop="-1" autostart="0" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>15.蓝色闪光播放器代码:<TABLE borderColor=#dee4fe cellSpacing=3 cellPadding=0 background= border=2><TBODY><TR><TD><TABLE align=center border=0><TBODY><TR><TD style="FILTER: alpha(opacity=60,style=3)"><P align=center><EMBED style="FILTER: Gray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBO DY></TABLE>16.带花边的播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed;BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0 bgColor=#00000><TBODY><TR><TD><TABLE borderColor=#000000 align=center border=1><TBODY><TR><TD><P align=center><EMBED style="FILTER: Xray" src=音乐网址width=400 height=35 type=audio/mpeg volume="0" autostart="false" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>17.粉色花边播放器代码:<TABLE style="BORDER-RIGHT: #ff69b4 3px dotted; BORDER-TOP: #ff69b4 3px dotted; BORDER-LEFT: #ff69b4 3px dotted; BORDER-BOTTOM: #ff69b4 3px dotted" cellSpacing=0 cellPadding=0 align=center bgColor=white><TBODY><TR><TD><TABLE borderColor=#ff69b4 align=center bgColor=#ffccf5 border=2><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"><P align=center><EMBED src=音乐网址width=300height=25 type=audio/mpeg volume="0" autostart="false" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>18.显示文件标签灰色播放器代码:<DIV><EMBED style="FILTER: Gray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>19显示文件标签棕色播放器代码:<DIV><EMBED style="FILTER: invert()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>20.显示文件标签黑色播放器代码:<DIV><EMBED style="FILTER: xray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="true" autostart="true" animationatstart="true"transparentatstart="true"></EMBED></div>21.连放播放器代码:<EMBED style="FILTER: Gray()" src=音乐网址width=500 height=35 type=audio/x-ms-wma controls="StatusBar,TACCtrl,ControlPanel" border="0" autostart="1" playcount="0" showtracker="1" volume="0"></EMBED>22.彩色播放器代码:<TABLE style="FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: 00CCFF; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana; FONT-VARIANT: normal" cellSpacing=0 cellPadding=0 width=140 border=0><TBODY><TR><TD style="BACKGROUND-COLOR: 00CCFF"><EMBED style="FILTER: invert alpha(opacity=50) WIDTH: 140px; HEIGHT: 45px" src=音乐链接地址 type=video/x-ms-asf autostart="FALSE" loop="-1"volume="0"></EMBED></TD></TR></TBODY></TABLE>本代码属性分析BACKGROUND-COLOR: 00CCFF 播放器颜色代码可以更换以变换播放器颜色23.透明播放器代码代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)xray(); WIDTH: 200px; HEIGHT: 40px"><TBODY><TR><TD><EMBED style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid" src=音乐链接地址 width=200 height=30 type=audio/x-mplayer2 loop="-1" autostart="0" volume="0" EnableContextMenu="0" showstatusbar="0" console="video"></TD></TR></TBODY></TABLE>。
基于java的音乐播放器的设计(源代码+实验报告)
主类MUSICPLAYER类:import java.util.*;import javax.swing.JSlider;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.io.BufferedOutputStream;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import javax.media.ControllerEvent;import javax.media.ControllerListener;import javax.media.EndOfMediaEvent;import javax.media.Manager;import javax.media.MediaLocator;import javax.media.NoPlayerException;import javax.media.Player;import javax.media.PrefetchCompleteEvent;import javax.media.Time;import javax.swing.ButtonGroup;import javax.swing.DefaultListModel;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JRadioButtonMenuItem;import javax.swing.JScrollBar;import javax.swing.JScrollPane;import javax.swing.filechooser.FileNameExtensionFilter;public class MusicPlayer implements ActionListener, Serializable,ControllerListener {private static final long serialVersionUID = 1L;private JFrame frame = null;private JPanel controlPanel = null;private JButton btnPlay = null;private JButton btnPre = null;private JButton btnNext = null;private JScrollPane listPane = null;private JList list = null;private DefaultListModel listModel = null;private JMenuBar menubar = null;private JMenu menuFile = null, menuAbout = null, menuMode = null;private JMenuItem itemOpen, itemOpens, itemExit, itemAbout;private JRadioButtonMenuItem itemSingle, itemSequence ,itemRandom;private ListItem currentItem = null;private static Player player = null;private boolean isPause = false;private int mode;private int currentIndex;private ImageIcon iconPlay = new ImageIcon("d:\\1.jpg");private ImageIcon iconPre = new ImageIcon("d:\\3.jpg");private ImageIcon iconNext = new ImageIcon("d:\\2.jpg");private ImageIcon iconPause = new ImageIcon("d:\\4.jpg");public static void main(String[] args){new MusicPlayer();}public MusicPlayer(){init();}public void init(){frame = new JFrame();frame.setTitle("音乐播放器");frame.setSize(400, 300);frame.setResizable(false);frame.setLocationRelativeTo(null);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);menubar = new JMenuBar();menuFile = new JMenu("文件");menuAbout = new JMenu("关于");menuMode = new JMenu("播放模式");itemOpen = new JMenuItem("添加文件");itemOpens = new JMenuItem("添加文件夹");itemExit = new JMenuItem("退出");itemAbout = new JMenuItem("关于");itemOpen.addActionListener(this);itemOpens.addActionListener(this);itemExit.addActionListener(this);itemAbout.addActionListener(this);itemSequence = new JRadioButtonMenuItem("顺序播放"); itemSequence.setSelected(true);itemSingle = new JRadioButtonMenuItem("单曲循环"); itemSequence.addActionListener(this);itemRandom = new JRadioButtonMenuItem("随机播放"); itemRandom.addActionListener(this);itemSingle.addActionListener(this);ButtonGroup bg = new ButtonGroup();bg.add(itemRandom);bg.add(itemSequence);bg.add(itemSingle);menuFile.add(itemOpen);menuFile.add(itemOpens);menuFile.add(itemExit);menuAbout.add(itemAbout);menuMode.add(itemSequence);menuMode.add(itemSingle);menuMode.add(itemRandom);menubar.add(menuFile);menubar.add(menuAbout);menubar.add(menuMode);frame.setJMenuBar(menubar);frame.setLayout(new BorderLayout());controlPanel = new JPanel();controlPanel.setLayout(new FlowLayout());btnPlay = new JButton(iconPlay);btnPre = new JButton(iconPre);btnNext = new JButton(iconNext);btnPlay.addActionListener(this);btnPre.addActionListener(this);btnNext.addActionListener(this);controlPanel.add(btnPre);controlPanel.add(btnPlay);controlPanel.add(btnNext);listPane = new JScrollPane();listModel = load();list = new JList(listModel);if (list.getSelectedIndex() == -1 && listModel.size() > 0){currentItem = (ListItem) listModel.get(0);list.setSelectedIndex(0);currentIndex=0;}listPane.getViewport().add(list);list.addMouseListener(new MouseAdapter(){public void mouseClicked(MouseEvent e){if (e.getClickCount() == 2){if(player!=null){player.close();btnPlay.setIcon(iconPlay);}currentIndex = list.locationToIndex(e.getPoint());currentItem = (ListItem) listModel.get(currentIndex);list.setSelectedIndex(currentIndex);play();}}});frame.setLayout(new BorderLayout());frame.add(controlPanel, BorderLayout.NORTH);frame.add(listPane, BorderLayout.CENTER);frame.setVisible(true);};public void actionPerformed(ActionEvent e){if (e.getSource() == itemOpen){// add filesJFileChooser jfc = new JFileChooser();FileNameExtensionFilter filter = new FileNameExtensionFilter("音乐文件", "mp3", "wav");jfc.setFileFilter(filter);jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);jfc.setMultiSelectionEnabled(true);if (jfc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION){File[] files = jfc.getSelectedFiles();for (File f : files){ListItem item = new ListItem(f.getName(), f.getAbsolutePath());listModel.addElement(item);}}}else if (e.getSource() == itemOpens){// add files in a directoryJFileChooser jfc = new JFileChooser();jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);if (jfc.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION){File directory = jfc.getSelectedFile();File[] files = directory.listFiles(new java.io.FileFilter(){public boolean accept(File f){if (f.getName().toLowerCase().endsWith(".mp3")|| f.getName().toLowerCase().endsWith(".wav"))return true;return false;}});for (File file : files){ListItem item = new ListItem(file.getName(), file.getAbsolutePath());listModel.addElement(item);}save(listModel);}}else if (e.getSource() == itemExit){System.exit(0);}else if (e.getSource() == itemAbout){JOptionPane.showMessageDialog(frame, "作者:陆鑫");}else if (e.getSource() == btnPlay){// play or pauseplay();}else if (e.getSource() == btnPre){pre();}else if (e.getSource() == btnNext){// next musicnext();}else if (e.getSource() == itemSequence){mode = 0;}else if (e.getSource() == itemSingle){mode = 1;}else if (e.getSource() == itemRandom){mode = 2;}}// play control/*** 播放*/public void play(){if (btnPlay.getIcon() == iconPlay){if (isPause){player.start();System.out.println("暂停结束");isPause = false;}else{try{player = Manager.createPlayer(new MediaLocator("file:"+ currentItem.getPath()));player.addControllerListener(this); // 提取媒体内容player.prefetch();}catch (NoPlayerException e1){e1.printStackTrace();}catch (IOException e1){e1.printStackTrace();}}btnPlay.setIcon(iconPause);}else{player.stop();isPause = true;System.out.println("暂停");btnPlay.setIcon(iconPlay);}}public void next(){if (currentIndex == listModel.getSize() - 1){currentIndex = 0;}else{currentIndex++;}currentItem = (ListItem) listModel.get(currentIndex);list.setSelectedIndex(currentIndex);Point p = list.indexToLocation(currentIndex);JScrollBar jScrollBar = listPane.getVerticalScrollBar();// 获得垂直转动条jScrollBar.setValue(p.y);// 设置垂直转动条位置btnPlay.setIcon(iconPlay);if (player != null)player.close();isPause = false;play();}public void rand(){list.setSelectedIndex((int)(Math.random()%(listModel.getSize()-1)));Pointp=list.indexToLocation((int)(Math.random()%(listModel.getSize()-1)));JScrollBar jScrollBar = listPane.getVerticalScrollBar();jScrollBar.setValue(p.y);btnPlay.setIcon(iconPlay);if (player != null)player.close();isPause = false;play();}public void pre(){if (currentIndex == 0){currentIndex = listModel.getSize() - 1;}else{currentIndex--;}currentItem = (ListItem) listModel.get(currentIndex);list.setSelectedIndex(currentIndex);Point p = list.indexToLocation(currentIndex);JScrollBar jScrollBar = listPane.getVerticalScrollBar();// 获得垂直转动条jScrollBar.setValue(p.y);// 设置垂直转动条位置btnPlay.setIcon(iconPlay);if (player != null){player.close();}isPause = false;play();}// end play controlpublic DefaultListModel load(){File file = new File("list.lst");DefaultListModel dlm = new DefaultListModel();if (file.exists()){try{ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));Integer size = (Integer) ois.readObject();if (size != 0){for (int i = 0; i < size; i++){ListItem item = (ListItem) ois.readObject();dlm.addElement(item);}}ois.close();return dlm;}catch (FileNotFoundException e){e.printStackTrace();}catch (IOException e){e.printStackTrace();}catch (ClassNotFoundException e){e.printStackTrace();}}return dlm;}public void save(DefaultListModel dlm){try{ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("list.lst")));Integer size = dlm.getSize();oos.writeObject(size);for (int i = 0; i < size; i++){ListItem item = (ListItem) dlm.get(i);oos.writeObject(item);}oos.close();}catch (Exception e){e.printStackTrace();}}public void controllerUpdate(ControllerEvent e) {if (e instanceof EndOfMediaEvent){if (mode == 0){// 顺序播放System.out.println("顺序播放");next();}else if (mode == 1){ // 单曲循环System.out.println("播放结束");player.setMediaTime(new Time(0));System.out.println("单曲循环");player.start();}else if (mode == 2){System.out.println("随机播放");rand();}return;}// 当提取媒体的内容结束if (e instanceof PrefetchCompleteEvent){System.out.println("开始播放");player.start();return;}}}LISTITEM类import java.io.Serializable;public class ListItem implements Serializable{private static final long serialVersionUID = 1L;private String name;private String path;public ListItem(){}public ListItem(String name, String path){ = name;this.path = path;}public String getName(){return name;}public void setName(String name){ = name;}public String getPath(){return path;}public void setPath(String path){this.path = path;}public String toString(){return name;}}基于java的音乐播放器的设计摘要:在信息,技术高速发展的今天,多媒体技术也越来越受到人们的重视。
音频播放器代码-代码大全
音频播放器代码-代码大全播放器样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode"VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo" VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode" VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo"VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"。
音频播放器源代码
音频播放器源代码1。
可以自动调节长度的音频播放器EMBED style="FILTER:alpha(opacity=15)"src=音乐地址height=45type=audio/mpeg autostart="true"loop="true"说明:这个播放器可以根据你的页面大小而自动调整大小,放文章处和文章宽度一样,想当首页背景音乐,就放在模块里面,就会变的和你一侧的宽度一样,解决了有的人一侧的播放器显示不完整的问题!再加一款大小正好放在一侧的音频播放器DIV EMBED codeBase=src=音乐地址=65 type=application/x-oleobject flename="mp"autostart="true"loop="true"/EMBED/DIV代码说明:AUTOSTART="TRUE"这里TRUE代表自动播放,如果换成FALSE则代表手动播放2。
几种简单的音频播放器代码代码一:embed src="背景音乐网址"hidden="true"autostart="true"loop="true"说明:hidden="true"隐藏播放不显示播放器的外观hidden="false"显示播放height="高度值"width="宽度值"。
autostart="true"当前页一载入则自动播放autostart="false"当前页一载入点击播放loop="true"无限次循环播放loop="false"就播放一次代码二:embed src="背景音乐网址"autostart="true"loop="-1"controls="ControlPanel"height="0"说明:不管是否最小化窗口都始终播放,直至关闭当前窗口为止loop="-1"无限次循环播放loop="1"播放一次改成1两次改成2依次类推width="0"height="0"隐藏播放width="123"height="100"外观大小,可自行调整自动播放无限次的播放器代码:embed autostart="true"loop="-1"controls="ControlPanel"height="0"src="音乐地址";播放一遍需要手动打开的音乐播放代码:/textarea embed src=音乐地址=2 autostart=False loop=False循环播放的音乐播放代码/textarea embed src=音乐地址=2 autostart=True loop=False循环播放+自动音乐播放代码/textarea embed src=音乐地址=2 autostart=True loop=True循环播放+自动音乐播放+隐藏播放器代码/textarea embed src=音乐地址=0 autostart=True loop=True自动音乐播放代码/textarea embed src=音乐地址=2 autostart=False loop=True隐藏播放器代码/textarea embed src=音乐地址=0 autostart=False loop=False循环播放+自动播放+播放器代码img src=":document.getElementById('Mlogo').innerHTML+='divstyle=\'position:absolute;top:;left:;\'iFRAME name=I1 src=\'音乐地址\'frameBorder=\'0\'width=\'\'scrolling=\'no\'height=\'\'/div';"几款播放器与播放器的美化EMBED src="歌曲地址"=50 type=audio/mpeg loop="-1"autostart="FALSE"volume="0"EMBED style="FILTER:invert()"src="歌曲地址"=50 type=audio/mpeg volume="0"autostart="FALSE"loop="true"EMBED style="FILTER:Xray"src=歌曲地址=05 type=audio/mpeg loop="-1"autostart="FALSE"volume="0"EMBED style="FILTER:GRAY()"src="歌曲地址"=45 type=audio/mpeg loop="-1"autostart="FALSE"volume="0"装饰美化你的播放器有了基本的款式后,我们就可以根据自己的想象力,巧用HTML的表格,根据自己的图片素材,装饰美化自己的播放器啦。
51单片机音乐播放器程序
51单片机音乐播放器程序#include //包含51单片机寄存器定义的头文件sbit sound=P3^6; //将sound位定义为P3.6unsigned int C; //储存定时器的定时常数//以下是C调低音的音频宏定义#define l_dao 262 //将"l_dao"宏定义为低音"1"的频率262Hz #define l_re 286 //将"l_re"宏定义为低音"2"的频率286Hz#define l_mi 311 //将"l_mi"宏定义为低音"3"的频率311Hz#define l_fa 349 //将"l_fa"宏定义为低音"4"的频率349Hz#define l_sao 392 //将"l_sao"宏定义为低音"5"的频率392Hz#define l_la 440 //将"l_a"宏定义为低音"6"的频率440Hz#define l_xi 494 //将"l_xi"宏定义为低音"7"的频率494Hz//以下是C调中音的音频宏定义#define dao 523 //将"dao"宏定义为中音"1"的频率523Hz#define re 587 //将"re"宏定义为中音"2"的频率587Hz#define mi 659 //将"mi"宏定义为中音"3"的频率659Hz#define fa 698 //将"fa"宏定义为中音"4"的频率698Hz#define sao 784 //将"sao"宏定义为中音"5"的频率784Hz#define la 880 //将"la"宏定义为中音"6"的频率880Hz#define xi 987 //将"xi"宏定义为中音"7"的频率523H//以下是C调高音的音频宏定义#define h_dao 1046 //将"h_dao"宏定义为高音"1"的频率1046Hz #define h_re 1174 //将"h_re"宏定义为高音"2"的频率1174Hz#define h_mi 1318 //将"h_mi"宏定义为高音"3"的频率1318Hz #define h_fa 1396 //将"h_fa"宏定义为高音"4"的频率1396Hz #define h_sao 1567 //将"h_sao"宏定义为高音"5"的频率1567Hz #define h_la 1760 //将"h_la"宏定义为高音"6"的频率1760Hz#define h_xi 1975 //将"h_xi"宏定义为高音"7"的频率1975Hz /*******************************************函数功能:1个延时单位,延时300ms******************************************/void delay(){unsigned char i,j;for(i=0;i<300;i++)for(j=0;j<300;j++);}/*******************************************函数功能:主函数******************************************/void main(void){unsigned char i,j;//以下是《知足》的一段简谱unsignedint code f[]={ dao,l_xi,dao ,sao,sao,dao,l_xi,dao,mi,dao,l_xi,dao,l_sao,mi,re,l_la,l_xi,dao,re,dao,l_xi,dao,sao,sao,la,xi,la,mi,la,xi,h_dao,sao,mi,mi,fa,mi,l_la,re,dao,dao,l_xi,dao,sao,sao,dao,l_xi,dao,mi,dao,l_xi,dao,l_sao,mi,re,l_la,l_xi,dao,re,dao,l_xi,dao,sao,sao,la,xi,h_dao,sao,la,xi,h_dao,sao,mi,mi,fa,mi,l_sao,re, dao,l_sao,h_dao,xi, la,fa,re, re,l_sao,xi,la,sao,re,dao,dao,re,mi,fa,fa,la,sao,mi,re,mi,fa,fa,sao,dao,h_dao,xi, la,fa,xi,h_dao,h_re, sao,h_re,xi,h_dao,la,xi,h_dao,h_re,sao,0xff}; //以0xff作为音符的结束标志//以下是简谱中每个音符的节拍//"4"对应4个延时单位,"2"对应2个延时单位,"1"对应1个延时单位unsigned char code JP[ ]={2,1,1,2,2,2,1,1,4,2,1,1,2,2,1,1,1,1,4,2,1,1,2,1,1,2,1,1,4,2,1,1,2,1,1,1,1,1,1,4,2,1,1,2,2,2,1,1,4,2,1,1,2,2,1,1,1,1,4,2,1,1,2,2,2,1,1,4,2,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,2,1,1,2,1,1,2,1,1,1,1,1,1,2,2,1,1,2,2,1,1,3,1/2,1/2,3,1/2,1/2,3,1,4,};EA=1; //开总中断ET0=1; //定时器T0中断允许TMOD=0x00; // 使用定时器T0的模式1(13位计数器)while(1) //无限循环{i=0; //从第1个音符f[0]开始播放while(f[i]!=0xff) //只要没有读到结束标志就继续播放{C=460830/f[i];TH0=(8192-C)/32; //可证明这是13位计数器TH0高8位的赋初值方法TL0=(8192-C)%32; //可证明这是13位计数器TL0低5位的赋初值方法TR0=1; //启动定时器T0for(j=0;j<="">delay(); //延时1个节拍单位TR0=0; //关闭定时器T0i++; //播放下一个音符}}}/*********************************************************** 函数功能:定时器T0的中断服务子程序,使P3.7引脚输出音频的方波************************************************************/ void Time0(void ) interrupt 1 using 1{sound=!sound; //将P3.7引脚输出电平取反,形成方波TH0=(8192-C)/32; //可证明这是13位计数器TH0高8位的赋初值方法TL0=(8192-C)%32; //可证明这是13位计数器TL0低5位的赋初值方法}。
C# _音乐播放器
目前网络上很多C#做的音乐播放器,但是功能不尽人意。
本人通过网上的播放器源码结合自身的知识做出一个比较好的播放器,供大家交流。
如图下:以下是播放器界面代码,新建一个项目CmTTPlayer,窗体文件名为Frm;namespace CmTTPlayer{partial class Frm{////// 必需的设计器变量。
///private ponentModel.IContainer components = null;////// 清理所有正在使用的资源。
////// 如果应释放托管资源,为true;否则为false。
protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows 窗体设计器生成的代码/// 设计器支持所需的方法- 不要/// 使用代码编辑器修改此方法的内容。
private void InitializeComponent(){ponents = new ponentModel.Container();ponentResourceManager resources = new ponentResourceManager(typeof(Frm));this.ribbonClientPanel1 = new DevComponents.DotNetBar.Ribbon.RibbonClientPanel();this.slider1 = new DevComponents.DotNetBar.Controls.Slider();this.tabControl1 = new DevComponents.DotNetBar.TabControl();this.tabControlPanel3 = new DevComponents.DotNetBar.TabControlPanel();this.lvMusicList = new System.Windows.Forms.ListView();this.columnHeader1 = new System.Windows.Forms.ColumnHeader();this.columnHeader2 = new System.Windows.Forms.ColumnHeader();this.columnHeader3 = new System.Windows.Forms.ColumnHeader();this.tabItem3 = new DevComponents.DotNetBar.TabItem(ponents);this.tabControlPanel1 = new DevComponents.DotNetBar.TabControlPanel();this.tabItem1 = new DevComponents.DotNetBar.TabItem(ponents);this.tabControlPanel2 = new DevComponents.DotNetBar.TabControlPanel();this.tabItem2 = new DevComponents.DotNetBar.TabItem(ponents);this.statusStrip1 = new System.Windows.Forms.StatusStrip();this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();this.tsmiOpenMusic = new System.Windows.Forms.ToolStripMenuItem();this.tsmiOpenFolderMusic = new System.Windows.Forms.ToolStripMenuItem();this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();this.tsmiOpenUrlMusic = new System.Windows.Forms.ToolStripMenuItem();this.toolStripDropDownButton2 = new System.Windows.Forms.ToolStripDropDownButton();this.panel2 = new System.Windows.Forms.Panel();this.btnPre = new DevComponents.DotNetBar.ButtonX();this.btnLast = new DevComponents.DotNetBar.ButtonX();this.btnPlayOrPause = new DevComponents.DotNetBar.ButtonX();this.btnStop = new DevComponents.DotNetBar.ButtonX();this.pnlTop = new System.Windows.Forms.Panel();this.lblMin = new bel();this.lblExit = new bel();this.progressBarX1 = new DevComponents.DotNetBar.Controls.ProgressBarX();this.chkAudioOnOff = new System.Windows.Forms.CheckBox();this.lblCurrentPosition = new bel();this.lblDuration = new bel();this.lblMusicName = new bel();this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(ponents);this.tsmenuDeleteChangeMusic = newSystem.Windows.Forms.ToolStripMenuItem();this.删除重复歌曲ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();this.toolStripMenuItem4 = new System.Windows.Forms.ToolStripSeparator();this.tsmenuClearList = new System.Windows.Forms.ToolStripMenuItem();this.timer1 = new System.Windows.Forms.Timer(ponents);this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(ponents);this.ribbonClientPanel1.SuspendLayout();((ponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();this.tabControl1.SuspendLayout();this.tabControlPanel3.SuspendLayout();this.statusStrip1.SuspendLayout();this.panel2.SuspendLayout();this.pnlTop.SuspendLayout();this.contextMenuStrip1.SuspendLayout();this.SuspendLayout();this.ribbonClientPanel1.CanvasColor = System.Drawing.SystemColors.Control;this.ribbonClientPanel1.Controls.Add(this.slider1);this.ribbonClientPanel1.Controls.Add(this.tabControl1);this.ribbonClientPanel1.Controls.Add(this.statusStrip1);this.ribbonClientPanel1.Controls.Add(this.panel2);this.ribbonClientPanel1.Controls.Add(this.pnlTop);this.ribbonClientPanel1.Dock = System.Windows.Forms.DockStyle.Fill;this.ribbonClientPanel1.Location = new System.Drawing.Point(0, 0); = "ribbonClientPanel1";this.ribbonClientPanel1.Size = new System.Drawing.Size(298, 545);this.ribbonClientPanel1.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground2;this.ribbonClientPanel1.Style.BackColorGradientAngle = 90;this.ribbonClientPanel1.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarBackground;this.ribbonClientPanel1.Style.BackgroundImagePosition = DevComponents.DotNetBar.eStyleBackgroundImage.Tile;this.ribbonClientPanel1.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid;this.ribbonClientPanel1.Style.BorderBottomWidth = 1;this.ribbonClientPanel1.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.BarDockedBorder;this.ribbonClientPanel1.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid;this.ribbonClientPanel1.Style.BorderLeftWidth = 1;this.ribbonClientPanel1.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid;this.ribbonClientPanel1.Style.BorderRightWidth = 1;this.ribbonClientPanel1.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid;this.ribbonClientPanel1.Style.BorderTopWidth = 1;this.ribbonClientPanel1.Style.Class = "RibbonClientPanel";this.ribbonClientPanel1.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center;this.ribbonClientPanel1.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText;this.ribbonClientPanel1.StyleMouseDown.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBackground2;this.ribbonClientPanel1.StyleMouseDown.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBackground;this.ribbonClientPanel1.StyleMouseDown.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedBorder;this.ribbonClientPanel1.StyleMouseDown.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemPressedText;this.ribbonClientPanel1.StyleMouseOver.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBackground2;this.ribbonClientPanel1.StyleMouseOver.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBackground;this.ribbonClientPanel1.StyleMouseOver.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotBorder;this.ribbonClientPanel1.StyleMouseOver.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemHotText;this.ribbonClientPanel1.TabIndex = 0;this.slider1.BackColor = System.Drawing.Color.Transparent;this.slider1.Location = new System.Drawing.Point(123, 523);this.slider1.Maximum = 1000; = "slider1";this.slider1.Size = new System.Drawing.Size(161, 20);this.slider1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;this.slider1.TabIndex = 3;this.slider1.Text = "音量:";this.slider1.V alue = 1000;this.slider1.V alueChanged += new System.EventHandler(this.slider1_Scroll);this.tabControl1.CanReorderTabs = true;this.tabControl1.Controls.Add(this.tabControlPanel3);this.tabControl1.Controls.Add(this.tabControlPanel1);this.tabControl1.Controls.Add(this.tabControlPanel2);this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;this.tabControl1.ForeColor = System.Drawing.SystemColors.ControlText;this.tabControl1.Location = new System.Drawing.Point(0, 96); = "tabControl1";this.tabControl1.SelectedTabFont = new System.Drawing.Font("宋体", 9F,System.Drawing.FontStyle.Bold);this.tabControl1.SelectedTabIndex = 0;this.tabControl1.Size = new System.Drawing.Size(298, 427);this.tabControl1.TabIndex = 9;this.tabControl1.TabLayoutType = DevComponents.DotNetBar.eTabLayoutType.FixedWithNavigationBox;this.tabControl1.Tabs.Add(this.tabItem3);this.tabControl1.Text = "tabControl1";this.tabControlPanel3.Controls.Add(this.lvMusicList);this.tabControlPanel3.Dock = System.Windows.Forms.DockStyle.Fill;this.tabControlPanel3.Location = new System.Drawing.Point(0, 26); = "tabControlPanel3";this.tabControlPanel3.Padding = new System.Windows.Forms.Padding(1);this.tabControlPanel3.Size = new System.Drawing.Size(298, 401);this.tabControlPanel3.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel3.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel3.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;this.tabControlPanel3.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));this.tabControlPanel3.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)| DevComponents.DotNetBar.eBorderSide.Bottom)));this.tabControlPanel3.Style.GradientAngle = 90;this.tabControlPanel3.TabIndex = 3;this.tabControlPanel3.TabItem = this.tabItem3;this.lvMusicList.Columns.AddRange(newSystem.Windows.Forms.ColumnHeader[] {this.columnHeader1,this.columnHeader2,this.columnHeader3});this.lvMusicList.ContextMenuStrip = this.contextMenuStrip1;this.lvMusicList.Dock = System.Windows.Forms.DockStyle.Fill;this.lvMusicList.FullRowSelect = true;this.lvMusicList.GridLines = true;this.lvMusicList.Location = new System.Drawing.Point(1, 1); = "lvMusicList";this.lvMusicList.Size = new System.Drawing.Size(296, 399);this.lvMusicList.TabIndex = 0;eCompatibleStateImageBehavior = false;this.lvMusicList.View = System.Windows.Forms.V iew.Details;this.lvMusicList.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lvMusicList_MouseDoubleClick);this.columnHeader1.Text = "";this.columnHeader1.Width = 30;this.columnHeader2.Text = "";this.columnHeader2.Width = 172;this.columnHeader3.Text = "";this.columnHeader3.Width = 75;this.tabItem3.AttachedControl = this.tabControlPanel3; = "tabItem3";this.tabItem3.Text = "本地歌曲";this.tabControlPanel1.Dock = System.Windows.Forms.DockStyle.Fill;this.tabControlPanel1.Location = new System.Drawing.Point(0, 26); = "tabControlPanel1";this.tabControlPanel1.Padding = new System.Windows.Forms.Padding(1);this.tabControlPanel1.Size = new System.Drawing.Size(298, 401);this.tabControlPanel1.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel1.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel1.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;this.tabControlPanel1.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));this.tabControlPanel1.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)| DevComponents.DotNetBar.eBorderSide.Bottom)));this.tabControlPanel1.Style.GradientAngle = 90;this.tabControlPanel1.TabIndex = 1;this.tabControlPanel1.TabItem = this.tabItem1;this.tabItem1.AttachedControl = this.tabControlPanel1; = "tabItem1";this.tabItem1.Text = "本地歌曲";this.tabControlPanel2.Dock = System.Windows.Forms.DockStyle.Fill;this.tabControlPanel2.Location = new System.Drawing.Point(0, 26); = "tabControlPanel2";this.tabControlPanel2.Padding = new System.Windows.Forms.Padding(1);this.tabControlPanel2.Size = new System.Drawing.Size(298, 401);this.tabControlPanel2.Style.BackColor1.Color =System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel2.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(247)))), ((int)(((byte)(222)))));this.tabControlPanel2.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;this.tabControlPanel2.Style.BorderColor.Color = System.Drawing.Color.FromArgb(((int)(((byte)(96)))), ((int)(((byte)(128)))), ((int)(((byte)(88)))));this.tabControlPanel2.Style.BorderSide = ((DevComponents.DotNetBar.eBorderSide)(((DevComponents.DotNetBar.eBorderSide.Left | DevComponents.DotNetBar.eBorderSide.Right)| DevComponents.DotNetBar.eBorderSide.Bottom)));this.tabControlPanel2.Style.GradientAngle = 90;this.tabControlPanel2.TabIndex = 2;this.tabControlPanel2.TabItem = this.tabItem2;this.tabItem2.AttachedControl = this.tabControlPanel2; = "tabItem2";this.tabItem2.Text = "网络歌曲";this.statusStrip1.BackColor = System.Drawing.Color.Transparent;this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.toolStripDropDownButton1,this.toolStripDropDownButton2});this.statusStrip1.Location = new System.Drawing.Point(0, 523); = "statusStrip1";this.statusStrip1.Size = new System.Drawing.Size(298, 22);this.statusStrip1.TabIndex = 10;this.statusStrip1.Text = "statusStrip1";this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;this.toolStripDropDownButton1.DropDownItems.AddRange(newSystem.Windows.Forms.ToolStripItem[] {this.tsmiOpenMusic,this.tsmiOpenFolderMusic,this.toolStripMenuItem1,this.tsmiOpenUrlMusic});this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; = "toolStripDropDownButton1";this.toolStripDropDownButton1.Size = new System.Drawing.Size(42, 20);this.toolStripDropDownButton1.Text = "文件"; = "tsmiOpenMusic";this.tsmiOpenMusic.Size = new System.Drawing.Size(154, 22);this.tsmiOpenMusic.Text = "添加本地歌曲";this.tsmiOpenMusic.Click += new System.EventHandler(this.tsmiOpenMusic_Click); = "tsmiOpenFolderMusic";this.tsmiOpenFolderMusic.Size = new System.Drawing.Size(154, 22);this.tsmiOpenFolderMusic.Text = "添加本地文件夹";this.tsmiOpenFolderMusic.Click += new System.EventHandler(this.tsmiOpenFolderMusic_Click); = "toolStripMenuItem1";this.toolStripMenuItem1.Size = new System.Drawing.Size(151, 6); = "tsmiOpenUrlMusic";this.tsmiOpenUrlMusic.Size = new System.Drawing.Size(154, 22);this.tsmiOpenUrlMusic.Text = "添加网络歌曲";this.toolStripDropDownButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;this.toolStripDropDownButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton2.Image")));this.toolStripDropDownButton2.ImageTransparentColor = System.Drawing.Color.Magenta; = "toolStripDropDownButton2";this.toolStripDropDownButton2.Size = new System.Drawing.Size(42, 20);this.toolStripDropDownButton2.Text = "系统";this.panel2.BackColor = System.Drawing.Color.Transparent;this.panel2.Controls.Add(this.btnPre);this.panel2.Controls.Add(this.btnLast);this.panel2.Controls.Add(this.btnPlayOrPause);this.panel2.Controls.Add(this.btnStop);this.panel2.Dock = System.Windows.Forms.DockStyle.Top;this.panel2.Location = new System.Drawing.Point(0, 66); = "panel2";this.panel2.Size = new System.Drawing.Size(298, 30);this.panel2.TabIndex = 8;this.btnPre.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;this.btnPre.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;this.btnPre.Enabled = false;this.btnPre.Location = new System.Drawing.Point(4, 3); = "btnPre";this.btnPre.Size = new System.Drawing.Size(72, 23);this.btnPre.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;this.btnPre.TabIndex = 5;this.btnPre.Text = "上一曲";this.btnPre.Click += new System.EventHandler(this.btnPre_Click);this.btnLast.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;this.btnLast.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;this.btnLast.Enabled = false;this.btnLast.Location = new System.Drawing.Point(220, 3); = "btnLast";this.btnLast.Size = new System.Drawing.Size(72, 23);this.btnLast.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;this.btnLast.TabIndex = 6;this.btnLast.Text = "下一曲";this.btnLast.Click += new System.EventHandler(this.btnLast_Click);this.btnPlayOrPause.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;this.btnPlayOrPause.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;this.btnPlayOrPause.Enabled = false;this.btnPlayOrPause.Location = new System.Drawing.Point(76, 3); = "btnPlayOrPause";this.btnPlayOrPause.Size = new System.Drawing.Size(72, 23);this.btnPlayOrPause.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;this.btnPlayOrPause.TabIndex = 4;this.btnPlayOrPause.Text = "开始播放";this.btnPlayOrPause.Click += new System.EventHandler(this.btnPlayOrPause_Click);this.btnStop.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;this.btnStop.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;this.btnStop.Enabled = false;this.btnStop.Location = new System.Drawing.Point(148, 3); = "btnStop";this.btnStop.Size = new System.Drawing.Size(72, 23);this.btnStop.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2003;this.btnStop.TabIndex = 7;this.btnStop.Text = "停止播放";this.btnStop.Click += new System.EventHandler(this.btnStop_Click);this.pnlTop.BackColor = System.Drawing.Color.Transparent;this.pnlTop.Controls.Add(this.lblMin);this.pnlTop.Controls.Add(this.lblExit);this.pnlTop.Controls.Add(this.progressBarX1);this.pnlTop.Controls.Add(this.chkAudioOnOff);this.pnlTop.Controls.Add(this.lblCurrentPosition);this.pnlTop.Controls.Add(this.lblDuration);this.pnlTop.Controls.Add(this.lblMusicName);this.pnlTop.Dock = System.Windows.Forms.DockStyle.Top;this.pnlTop.Location = new System.Drawing.Point(0, 0); = "pnlTop";this.pnlTop.Size = new System.Drawing.Size(298, 66);this.pnlTop.TabIndex = 3;this.pnlTop.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pnlTop_MouseMove);this.pnlTop.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlTop_MouseDown);this.lblMin.AutoSize = true;this.lblMin.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.lblMin.Location = new System.Drawing.Point(260, 2); = "lblMin";this.lblMin.Size = new System.Drawing.Size(17, 16);this.lblMin.TabIndex = 10;this.lblMin.Text = "-";this.lblMin.Click += new System.EventHandler(this.lblMin_Click);this.lblExit.AutoSize = true;this.lblExit.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));this.lblExit.Location = new System.Drawing.Point(279, 3); = "lblExit";this.lblExit.Size = new System.Drawing.Size(15, 14);this.lblExit.TabIndex = 9;this.lblExit.Text = "X";this.lblExit.Click += new System.EventHandler(this.lblExit_Click);this.progressBarX1.BackColor = System.Drawing.Color.Transparent;this.progressBarX1.Dock = System.Windows.Forms.DockStyle.Bottom;this.progressBarX1.Location = new System.Drawing.Point(0, 56); = "progressBarX1";this.progressBarX1.Size = new System.Drawing.Size(298, 10);this.progressBarX1.TabIndex = 8;this.chkAudioOnOff.AutoSize = true;this.chkAudioOnOff.FlatStyle = System.Windows.Forms.FlatStyle.Flat;this.chkAudioOnOff.Location = new System.Drawing.Point(247, 20); = "chkAudioOnOff";this.chkAudioOnOff.Size = new System.Drawing.Size(45, 16);this.chkAudioOnOff.TabIndex = 1;this.chkAudioOnOff.Text = "静音";eVisualStyleBackColor = true;this.chkAudioOnOff.CheckedChanged += newSystem.EventHandler(this.chkAudioOnOff_CheckedChanged);this.lblCurrentPosition.AutoSize = true;this.lblCurrentPosition.Location = new System.Drawing.Point(239, 39); = "lblCurrentPosition";this.lblCurrentPosition.Size = new System.Drawing.Size(53, 12);this.lblCurrentPosition.TabIndex = 3;this.lblCurrentPosition.Text = "00:00:00";this.lblDuration.AutoSize = true;this.lblDuration.Location = new System.Drawing.Point(4, 39); = "lblDuration";this.lblDuration.Size = new System.Drawing.Size(53, 12);this.lblDuration.TabIndex = 2;this.lblDuration.Text = "00:00:00";this.lblMusicName.AutoSize = true;this.lblMusicName.Location = new System.Drawing.Point(4, 20); = "lblMusicName";this.lblMusicName.Size = new System.Drawing.Size(77, 12);this.lblMusicName.TabIndex = 1;this.lblMusicName.Text = "暂无音乐文件";this.contextMenuStrip1.Items.AddRange(newSystem.Windows.Forms.ToolStripItem[] {this.tsmenuDeleteChangeMusic,this.删除重复歌曲ToolStripMenuItem,this.toolStripMenuItem4,this.tsmenuClearList}); = "contextMenuStrip1";this.contextMenuStrip1.Size = new System.Drawing.Size(143, 76); = "tsmenuDeleteChangeMusic";this.tsmenuDeleteChangeMusic.Size = new System.Drawing.Size(142, 22);this.tsmenuDeleteChangeMusic.Text = "删除选中歌曲";this.tsmenuDeleteChangeMusic.Click += new System.EventHandler(this.tsmiDeleteChangeMusic_Click);this.删除重复歌曲 = "删除重复歌曲ToolStripMenuItem";this.删除重复歌曲ToolStripMenuItem.Size = new System.Drawing.Size(142, 22);this.删除重复歌曲ToolStripMenuItem.Text = "删除重复歌曲"; = "toolStripMenuItem4";this.toolStripMenuItem4.Size = new System.Drawing.Size(139, 6); = "tsmenuClearList";this.tsmenuClearList.Size = new System.Drawing.Size(142, 22);this.tsmenuClearList.Text = "清空歌曲列表";this.tsmenuClearList.Click += new System.EventHandler(this.tsmiClearList_Click);this.timer1.Tick += new System.EventHandler(this.timer1_Tick);this.notifyIcon1.BalloonTipIcon = ;this.notifyIcon1.Text = "草莓¢音乐播放器";this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(298, 545);this.Controls.Add(this.ribbonClientPanel1);this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;this.MaximizeBox = false; = "Frm";this.Opacity = 0;this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = "草莓¢音乐播放器";this.Load += new System.EventHandler(this.Frm_Load);this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Frm_FormClosing);this.Resize += new System.EventHandler(this.Frm_Resize);this.ribbonClientPanel1.ResumeLayout(false);this.ribbonClientPanel1.PerformLayout();((ponentModel.ISupportInitialize)(this.tabControl1)).EndInit();this.tabControl1.ResumeLayout(false);this.tabControlPanel3.ResumeLayout(false);this.statusStrip1.ResumeLayout(false);this.statusStrip1.PerformLayout();this.panel2.ResumeLayout(false);this.pnlTop.ResumeLayout(false);this.pnlTop.PerformLayout();this.contextMenuStrip1.ResumeLayout(false);this.ResumeLayout(false);}private DevComponents.DotNetBar.Ribbon.RibbonClientPanel ribbonClientPanel1;private DevComponents.DotNetBar.ButtonX btnLast;private DevComponents.DotNetBar.ButtonX btnStop;private DevComponents.DotNetBar.ButtonX btnPlayOrPause;private DevComponents.DotNetBar.ButtonX btnPre;private System.Windows.Forms.Panel panel2;private DevComponents.DotNetBar.TabControl tabControl1;private DevComponents.DotNetBar.TabControlPanel tabControlPanel1;private DevComponents.DotNetBar.TabItem tabItem1;private DevComponents.DotNetBar.TabControlPanel tabControlPanel2;private DevComponents.DotNetBar.TabItem tabItem2;private System.Windows.Forms.StatusStrip statusStrip1;private System.Windows.Forms.ToolStripDropDownButtontoolStripDropDownButton1;private System.Windows.Forms.ToolStripMenuItem tsmiOpenMusic;private System.Windows.Forms.ToolStripMenuItem tsmiOpenFolderMusic;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;private System.Windows.Forms.ToolStripMenuItem tsmiOpenUrlMusic;private System.Windows.Forms.Timer timer1;private DevComponents.DotNetBar.Controls.Slider slider1;private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton2;private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;private System.Windows.Forms.ToolStripMenuItem tsmenuDeleteChangeMusic;private System.Windows.Forms.ToolStripMenuItem 删除重复歌曲ToolStripMenuItem;private System.Windows.Forms.ToolStripSeparator toolStripMenuItem4;private System.Windows.Forms.ToolStripMenuItem tsmenuClearList;private System.Windows.Forms.NotifyIcon notifyIcon1;private System.Windows.Forms.Panel pnlTop;private DevComponents.DotNetBar.Controls.ProgressBarX progressBarX1;private System.Windows.Forms.CheckBox chkAudioOnOff;private bel lblCurrentPosition;private bel lblDuration;private bel lblMusicName;private DevComponents.DotNetBar.TabControlPanel tabControlPanel3;private System.Windows.Forms.ListView lvMusicList;private System.Windows.Forms.ColumnHeader columnHeader1;private System.Windows.Forms.ColumnHeader columnHeader2;private System.Windows.Forms.ColumnHeader columnHeader3;private DevComponents.DotNetBar.TabItem tabItem3;private bel lblExit;private bel lblMin;}}以下是功能模块代码:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;using System.Xml;using System.Diagnostics;using System.IO;namespace CmTTPlayer{public partial class Frm : Form{////// 强行释放内存资源///////////////[DllImport("kernel32", EntryPoint = "SetProcessWorkingSetSize", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]public static extern int SetProcessWorkingSetSize(int hProcess, int dwMinimumWorkingSetSize, int dwMaximumWorkingSetSize);private Media media = new Media();//自增长序号private int number = 1;//当前播放曲目Indexprivate int changeV alue = 0;//当前播放曲目自增长序号private string changeItemText = "1";private Timer tmrShow = new Timer();Timer tmrClose;private int startX, StartY;public Frm(){InitializeComponent();}////// 初始化窗体数据/////////private void Frm_Load(object sender, EventArgs e){//获取进程的模块名称string mName = Process.GetCurrentProcess().MainModule.ModuleName;//返回没有扩展名的模块名称string pName = Path.GetFileNameWithoutExtension(mName);Process[] myProcess = Process.GetProcessesByName(pName);if (myProcess.Length > 1){MessageBox.Show("当前程序已经运行", "系统提示", MessageBoxButtons.OK, rmation);this.Dispose();Application.ExitThread();}else{this.tmrShow.Tick += new EventHandler(this.tmrShow_Tick);this.tmrShow.Enabled = true;}//设置图标this.Icon = Icon.ExtractAssociatedIcon("CmTTPlayer.ico");this.notifyIcon1.Icon = Icon.ExtractAssociatedIcon("CmTTPlayer.ico");media.SetAudioSource(Media.AudioSource.H);XmlDocument xmlDoc = new XmlDocument();//获取当前应用程序路径string path = Process.GetCurrentProcess().MainModule.FileName.Substring(0, Process.GetCurrentProcess()stIndexOf("\\"));//加载Xml文件xmlDoc.Load(path + "\\MusicFile.xml");XmlNode root = xmlDoc.SelectSingleNode("musiclist");//查找XmlNodeList xnl = root.ChildNodes;for (int i = 0; i < xnl.Count; i++){ListViewItem item = new ListViewItem(number.ToString());item.SubItems.AddRange(new string[] { root.ChildNodes[i].Attributes["genre"].V alue, root.ChildNodes[i].Attributes["lenght"].V alue });item.Tag = root.ChildNodes[i].Attributes["filename"].V alue;lvMusicList.Items.Add(item);number++;Application.DoEvents();}//在加载事件中执行以下SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle.ToInt32(), -1, -1);}。
音乐播放器代码
音乐播放器的编程代码#include<windows.h>#include<mmsystem.h>#include<digitalv.h>#include<commctrl.h>#include<stdio.h>#include "resource.h"int GetFileName(TCHAR *FileName, HANDLE hwnd,char *lei){//该函数实现“打开文件名填充在FileName数组中,char *lei为需要打开的文件类型,如:mp3, 则传入"mp3"int i;int j;int len;char c[100]={0};char a[]="(*.)\0*.\0\0";OPENFILENAME FileNames;static char szFileName[MAX_PATH];static char szTitleName [MAX_PATH] ;static TCHAR szFilter[100] = {0};len = strlen(lei);c[0]=a[0];c[1]=a[1];c[2]=a[2];for(i=0;i<len;i++){c[3+i]=lei[i];}c[3+i]=a[3];c[4+i]=a[4];c[5+i]=a[5];c[6+i]=a[6];for(j=0;j<len;j++){c[7+i+j]=lei[j];}c[7+i+j]=a[7];c[8+i+j]=a[8];memcpy(szFilter, c,100);FileNames.lStructSize = sizeof (OPENFILENAME) ;FileNames.hwndOwner = hwnd ;FileNames.hInstance = NULL ;FileNames.lpstrFilter = szFilter ;FileNames.lpstrCustomFilter = NULL ;FileNames.nMaxCustFilter = 0 ;FileNames.nFilterIndex = 0 ;FileNames.lpstrFile = szFileName ;FileNames.nMaxFile = MAX_PATH ;FileNames.lpstrFileTitle = szTitleName ;FileNames.nMaxFileTitle = MAX_PATH ;FileNames.lpstrInitialDir = NULL ;FileNames.lpstrTitle = NULL ;FileNames.Flags = 0 ;FileNames.nFileOffset = 0 ;FileNames.nFileExtension = 0 ;FileNames.lpstrDefExt = NULL;FileNames.lCustData = 0 ;FileNames.lpfnHook = NULL ;FileNames.lpTemplateName = NULL ;GetOpenFileName(&FileNames);for(i=0,j=0; szFileName[i]; i++,j++){if(szFileName[i]=='\\'){FileName[j++] = szFileName[i];FileName[j]='\\';}elseFileName[j]=szFileName[i];}FileName[j] = 0;return 0;}LONG CALLBACKDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {static char FileName[250];static char buffer[100];static int iPosition;static HANDLE hSlider;static MCI_PLAY_PARMS mciPlay;static MCI_OPEN_PARMS mciOpen;static MCI_DGV_SETAUDIO_PARMS mciSetAudioPara;memset(FileName, 0, sizeof(FileName) );switch(message){case WM_CLOSE:EndDialog( hwnd, 0);return 0;case WM_INITDIALOG:hSlider = GetDlgItem(hwnd, IDC_SLIDER1);SendMessage(hSlider, TBM_SETPOS, TRUE, 20);mciSetAudioPara.dwValue = 200;mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;return 0;//音量调节的核心代码case WM_HSCROLL:switch(LOWORD(wParam) ){case SB_THUMBPOSITION:case SB_PAGERIGHT:case SB_PAGELEFT:iPosition = SendMessage(hSlider, TBM_GETPOS, 0, 0);mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;mciSetAudioPara.dwValue = iPosition*10;mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_V ALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);return 0;default:return 0;}return 0;case WM_COMMAND:switch(LOWORD(wParam) ){case IDB_SCAN:_GetFileName(FileName, hwnd, "mp3");//打开文件SetDlgItemText(hwnd, IDC_EDIT, FileName);SetFocus(GetDlgItem(hwnd, IDB_PLAY) );//开始播放mciOpen.lpstrElementName=(char *)malloc(250*sizeof(char));GetDlgItemText(hwnd, IDC_EDIT, mciOpen.lpstrElementName, 250);mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT, (DWORD)&mciOpen);mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);//设置初始音量mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_V ALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);return 0;//从暂停中恢复播放case IDB_PLAY:mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);return 0;//暂停case IDB_PAUSE:mciSendCommand(mciOpen.wDeviceID, MCI_PAUSE, MCI_NOTIFY, (DWORD)&mciPlay);return 0;default:return 0;}return 0;default:return 0;}}LONG WINAPIWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){InitCommonControls();DialogBoxParam(hInstance, IDD_DIALOG1, NULL, DlgProc,NULL);return 0;}。
音乐播放器(VB编程源代码)
音乐播放器设计一、先来欣赏一下本音乐播放器的最终效果吧:设计思路很简单,即下面两个窗体的设计。
二、主窗体(form1)界面设计如下:主窗体(form1)代码如下:Dim t As Integer, a As BooleanDim p As Integer, b, w As Boolean, onePrivate Sub allclear_Click()'清空播放列表List1.ClearWMP1.currentPlaylist.ClearForm1.Caption = "无任何曲目"End SubPrivate Sub allloop_Click()'全部循环播放Timer3.Enabled = Falseallloop.Checked = Trueoneloop.Checked = Falserand.Checked = Falserule.Checked = FalseCall WMP1.settings.setMode("loop", True)End SubPrivate Sub Form_Load()'初始化Form1.Height = 7800w = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueLabel2.Caption = "00:00"'第一次打开时创建文件If Dir("filepath.text") = "" And Dir("C:\music.txt") = "" ThenOpen "C:\filepath.txt" For Output As #1Close #1Open "C:\music.txt" For Output As #2Close #2End If'读取文件Open "C:\filepath.txt" For Input As #1Open "C:\music.txt" For Input As #2Do While Not EOF(1)Input #1, XInput #2, YIf Dir(X) <> "" ThenList1.AddItem (List1.ListCount + 1) & "." & YCall WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(X)) End IfLoopClose #1Close #2'初始化If List1.ListCount <> 0 Then List1.Selected(0) = TruePicture3(0).Width = 114Picture3(0).Height = 52Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52Picture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23a = FalseCall WMP1.settings.setMode("shuffle", False) '初始设置为顺序播放Label1.Caption = Mid(List1.List(0), InStr(List1.List(0), ".") + 1)sd1.Value = 50 '音量设置为50%End SubPrivate Sub List1_DblClick()'双击播放Call WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))a = Truet = 1Picture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End SubPrivate Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If X > List1.Width - 430 Thenw = TrueEnd IfEnd SubPrivate Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '伸缩播放列表If X > List1.Width - 430 And X < List1.Width - 330 ThenList1.MousePointer = 9ElseList1.MousePointer = 0End IfIf w = True And X > 1500 And X < 5800 ThenList1.Width = XEnd IfEnd SubPrivate Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)w = FalseEnd SubPrivate Sub List1_Scroll()List1.MousePointer = 0End SubPrivate Sub oneloop_Click()'单曲循环allloop.Checked = Falseoneloop.Checked = Truerand.Checked = Falserule.Checked = FalseTimer3.Enabled = TrueEnd SubPrivate Sub Pc13_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) '播放进度控制If WMP1.playState = wmppsPlaying ThenWMP1.Controls.currentPosition = WMP1.currentMedia.duration * X / 233Pc13.ClsPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - X, 0, 233, 17End IfEnd SubPrivate Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '切换图片If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52End SubPrivate Sub Picture10_Click()'打开搜索窗体Form2.ShowEnd SubPrivate Sub Picture11_Click()'设置静音sd1.Value = 0Picture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 38, 0, 19, 23End SubPrivate Sub Picture3_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)If Index = 0 ThenIf a = True ThenCall WMP1.Controls.pause '播放ElseCall WMP1.Controls.play '暂停End IfEnd IfIf Index = 3 Thenp = 1Call WMP1.Controls.Next '下一首p = 0End IfIf Index = 2 Thenp = 1Call WMP1.Controls.previous '上一首p = 0End IfIf Index = 4 Then Call WMP1.Controls.stop '停止播放'打开音乐文件If Index = 1 ThenCommonDialog1.DialogTitle = "打开音乐文件"CommonDialog1.Filter = "mp3|*.mp3|wma|*.wma"CommonDialog1.InitDir = "D:\"CommonDialog1.ShowOpenfname = CommonDialog1.FileTitlegname = CommonDialog1.FileNameIf fname <> "" Thenn = Len(fname)For i = 0 To List1.ListCount - 1If Right(List1.List(i), n - 4) = Left(fname, n - 4) ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(i)) '播放添加后的歌曲Timer1.Enabled = TrueList1.ListIndex = iExit SubEnd IfNextList1.AddItem (List1.ListCount + 1) & "." & Left(fname, n - 4) '歌曲无重复则添加到播放列表,否则不再添加Call WMP1.currentPlaylist.insertItem(WMP1.currentPlaylist.Count, WMP1.newMedia(gname))List1.ListIndex = List1.ListCount - 1List1.Selected(i) = TrueCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(List1.ListIndex))Timer1.Enabled = TrueEnd IfEnd IfEnd SubPrivate Sub Picture3_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)'根据不同情况切换图片,实现动态按钮功能If Index = 0 ThenIf t = 0 ThenIf X < 6 Or X > 80 Or Y < 6 Or Y > 48 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52ElsePicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 228, 0, 114, 52End IfEnd IfIf t = 1 ThenIf X < 6 Or X > 80 Or Y < 6 Or Y > 48 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52ElsePicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 228, 0, 114, 52End IfEnd IfEnd IfIf Index = 1 ThenIf X < 6 Or X > 55 Or Y < 6 Or Y > 48 ThenPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 60, 0, 60, 52End IfEnd IfIf Index = 2 ThenIf X < 6 Or X > 65 Or Y < 6 Or Y > 48 ThenPicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52ElsePicture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 83, 0, 83, 52End IfEnd IfIf Index = 3 ThenIf X < 6 Or X > 65 Or Y < 6 Or Y > 48 ThenPicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52ElsePicture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 166, 0, 83, 52End IfEnd IfIf Index = 4 ThenIf X < 6 Or X > 55 Or Y < 6 Or Y > 48 ThenPicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52ElsePicture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 120, 0, 60, 52End IfEnd IfEnd SubPrivate Sub Picture4_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) '图片切换'If t = 0 ThenPicture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfIf t = 1 ThenPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52End IfPicture3(1).PaintPicture Picture2(2).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(2).PaintPicture Picture2(3).Picture, 0, 0, 83, 52, 0, 0, 83, 52Picture3(4).PaintPicture Picture2(5).Picture, 0, 0, 60, 52, 0, 0, 60, 52Picture3(3).PaintPicture Picture2(4).Picture, 0, 0, 83, 52, 0, 0, 83, 52End SubPrivate Sub Picture5_Click()'显示或隐藏播放列表If b = 0 ThenForm1.Width = 5940Form1.Height = 3900b = 1Picture5.ToolTipText = "显示播放列表"ElseForm1.Width = 5940Form1.Height = 7800b = 0Picture5.ToolTipText = "隐藏播放列表"End IfEnd SubPrivate Sub Picture6_Click()'最小化窗体Form1.WindowState = 1End SubPrivate Sub Picture7_Click()'关闭窗体之前保存播放列表数据Open "C:\filepath.txt" For Output As #1Open "C:\music.txt" For Output As #2For i = 0 To List1.ListCount - 1n = InStr(List1.List(i), ".")Write #1, WMP1.currentPlaylist.Item(i).sourceURLWrite #2, Mid(List1.List(i), n + 1)NextClose #1Close #2EndEnd SubPrivate Sub Picture8_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) '播放模式设置菜单PopupMenu menusetEnd SubPrivate Sub Picture9_Click()'删除菜单PopupMenu gclearEnd SubPrivate Sub rand_Click()'随机播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Truerule.Checked = FalseCall WMP1.settings.setMode("shuffle", True)End SubPrivate Sub rule_Click()'顺序播放Timer3.Enabled = Falseallloop.Checked = Falseoneloop.Checked = Falserand.Checked = Falserule.Checked = TrueCall WMP1.settings.setMode("shuffle", False)End SubPrivate Sub sd1_Change()'音量控制条WMP1.settings.volume = sd1.Valuesd1.ToolTipText = "音量" & sd1.Value & "%'"If sd1.Value = 0 Then sd1.ToolTipText = "静音"If sd1.Value = 100 Then sd1.ToolTipText = "最大音量"If sd1.Value <> 0 ThenPicture11.PaintPicture Picture12.Picture, 0, 0, 19, 23, 0, 0, 19, 23End IfEnd SubPrivate Sub select_Click()'删除选中项For i = 0 To List1.ListCount - 1If List1.Selected(i) ThenList1.RemoveItem (i)m = iCall WMP1.currentPlaylist.RemoveItem(WMP1.currentPlaylist.Item(i)) Exit ForEnd IfNextFor i = 0 To List1.ListCount - 1n = InStr(List1.List(i), ".")List1.List(i) = (i + 1) & "." & Mid(List1.List(i), n + 1)NextIf List1.ListCount = 0 Then Exit SubIf List1.ListCount = m ThenList1.Selected(m - 1) = TrueElseList1.Selected(m) = TrueEnd IfEnd SubPrivate Sub Timer1_Timer()'更新播放动态If WMP1.currentPlaylist.Count <> 0 ThenIf WMP1.playState = 3 ThenLabel2.Caption = WMP1.Controls.currentPositionStringPicture3(0).PaintPicture Picture2(1).Picture, 0, 0, 114, 52, 0, 0, 114, 52a = Truet = 1Picture3(0).ToolTipText = "播放"ElseLabel2.Caption = "00:00"Picture3(0).PaintPicture Picture2(0).Picture, 0, 0, 114, 52, 0, 0, 114, 52a = Falset = 0Picture3(0).ToolTipText = "暂停"End IfEnd IfIf WMP1.playState = 2 ThenLabel2.Caption = WMP1.Controls.currentPositionString '显示播放进度(时间)End IfPc13.ClsIf WMP1.playState = 3 Or WMP1.playState = 2 ThenPc13.PaintPicture Pc14.Picture, 0, 0, 233, 17, 234 - 233 * WMP1.Controls.currentPosition / WMP1.currentMedia.duration, 0, 233, 17End IfEnd SubPrivate Sub Timer2_Timer()'标题动态显示If WMP1.currentPlaylist.Count <> 0 ThenIf WMP1.playState <> 3 ThenForm1.Caption = "暂停播放——" + WMP1.currentMedia.getItemInfo("title")ElseForm1.Caption = "正在播放——" + WMP1.currentMedia.getItemInfo("title")End IfEnd IfEnd SubPrivate Sub Timer3_Timer()'单曲循环If WMP1.currentMedia.duration - 0.5 < WMP1.Controls.currentPosition ThenCall WMP1.Controls.playItem(WMP1.currentPlaylist.Item(one))End IfEnd SubPrivate Sub WMP1_OpenStateChange(ByVal NewState As Long)n = 0If p = 0 ThenFor i = 0 To List1.ListCount - 1If WMP1.currentPlaylist.Item(i).getItemInfo("title") <> WMP1.currentMedia.getItemInfo("title") Thenn = n + 1ElseExit ForEnd IfNextone = nLabel1.Caption = Mid(List1.List(n), InStr(List1.List(n), ".") + 1) '显示正在播放的曲目List1.Selected(n) = TrueEnd IfLabel3.Caption = WMP1.currentMedia.durationString '显示歌曲总长End Sub三、副窗体(form1)界面设计如下:说明:该窗体用于搜索电脑已有歌曲(本音乐播放器的特色所在)副窗体(form1)代码如下:Dim n As Integer, temp(10000) As String, m As IntegerPrivate Sub choose_Click()'选择全部歌曲For i = 0 To List2.ListCount - 1List2.Selected(i) = TrueNext iEnd SubPrivate Sub choosenone_Click()'清除选择For i = 0 To List2.ListCount - 1List2.Selected(i) = FalseNext iEnd SubPrivate Sub Command1_Click()'搜索歌曲并保存Open "C:\searchresult.txt" For Output As #1Open "C:\geresult.txt" For Output As #2List2.ClearDim s As StringCall find(Combo1.Text)If m = n Then s = MsgBox("搜索完毕", vbInformation, "提示")Close #1Close #2End SubPrivate Sub Command2_Click()'将选中歌曲添加到播放列表For i = 0 To List2.ListCount - 1t = 0If List2.Selected(i) = True ThenFor j = 0 To Form1.List1.ListCount - 1n = Len(List2.List(i))If Right(Form1.List1.List(j), n) = List2.List(i) Then t = t + 1: Exit ForNextIf t = 0 ThenForm1.List1.AddItem (Form1.List1.ListCount + 1) & "." & List2.List(i)Call Form1.WMP1.currentPlaylist.insertItem(Form1.WMP1.currentPlaylist.Count, Form1.WMP1.newMedia(List3.List(i)))End IfEnd IfNext iFor i = 1 To List2.SelCountFor j = 0 To List2.ListCount - 1If List2.Selected(j) ThenList2.RemoveItem jList3.RemoveItem jExit ForEnd IfNext jNext is = MsgBox("已添加到播放列表", vbInformation, "提示")End SubPrivate Sub Command3_Click()'读取文件(上次最后一次搜索结果)If Dir("C:\searchresult.txt") <> "" And Dir("C:\geresult.txt") <> "" ThenOpen "C:\searchresult.txt" For Input As #1Open "C:\geresult.txt" For Input As #2Do While Not EOF(1)Input #1, XInput #2, YList3.AddItem XList2.AddItem YLoopClose #1Close #2s = MsgBox("上次搜索结果读取完成!", vbInformation, "提示")Elses = MsgBox("没有任何搜索记录!", vbInformation, "提示")End IfEnd SubPrivate Sub Form_Load()'选择搜索条件即路径和文件格式Combo1.Text = Combo1.List(0)Combo2.Text = Combo2.List(0)Form2.Picture = LoadPicture("")End SubPrivate Function find1() '文件搜索函数Dim i As StringDim a As Integer, b As Integera = m:b = nDim k As IntegerFor k = a To bIf temp(k) = "" Then Exit Functionfind (temp(k))NextEnd Function'*************************************'获取该路径下的文件,并且存储目录文件的路径******************************************Private Function find(ByVal path As String) '文件搜索函数Dim i As Stringm = ni = Dir(path, vbDirectory)Do While i <> ""If i <> "." And i <> ".." ThenIf (GetAttr(path & i) And vbDirectory) <> 0 Thentemp(n) = path & i & "\"n = n + 1ElseDoEventsIf Right(i, Len(Combo2.Text)) = Combo2.Text ThenList3.AddItem path & iWrite #1, path & iWrite #2, Left(i, Len(i) - 4)List2.AddItem Left(i, Len(i) - 4)End IfEnd IfEnd Ifi = DirLoopfind1End Function总结:本音乐播放器的界面还可以设计的更加漂亮好看,这个就得发挥你的界面设计能力咯!以上播放器的设计还有很多可以改善的地方,比如代码能否更加简化?还缺少哪些功能?如何更加赏心悦目?这些就交给你自己去完善咯!另外,为了方便有兴趣的人更好的理解整个设计过程,我已共享该音乐播放器程序设计的整个工程文件(本程序用到的图片也含有)到以下网址:可以下载看看,希望对你有所帮助!。
音乐播放器程序源代码及注释
音乐播放器程序源代码及注释:#include <reg52.h>#define uchar unsigned char#define uint unsigned intsbit duan=P2^6;sbit key1=P3^2;//按key1可切换花样sbit key2=P3^3;//按key2可切换歌曲sbit fm=P2^4;//蜂鸣器连续的IO口sbit P30=P3^0;//矩阵键盘的一列uchar code huayang1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf};//花样1uchar code huayang2[]={0x7f,0xfe,0xbf,0xfd,0xdf,0xfb,0xef,0xf7,0xef,0xfb,0xdf,0xfd,0xbf,0xfe};//花样2uchar code huayang3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; char codehuayang4[]={ 0x55,0xaa,0xcc,0x33,0x99,0x66,0x0f,0xf0}; uchar count1;//花样标志uchar count2;//歌曲标志uchar timeh,timel,i;//编程规则:字节高位是简谱,低位是持续时间,//代表多少个十六分音符//1-7代表中央C调,8-E代表高八度,0代表停顿//最后的0是结束标志uchar code qnzl[]={ //千年之恋0x12,0x22,0x34,0x84,0x74,0x54,0x38,0x42,0x32,0x22,0x42,0x34,0x84,0 x72,0x82,0x94,0xA8,0x08,//前奏0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//竹林的灯火到过的沙漠0x32,0x31,0x21,0x32,0x82,0x71,0x81,0x71,0x51,0x32,0x22,//七色的国度不断飘逸风中0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//有一种神秘灰色的旋涡0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,//将我卷入了迷雾中0x63,0xA1,0xA2,0x62,0x92,0x82,0x52,//看不清的双手0x31,0x51,0x63,0x51,0x63,0x51,0x63,0x51,0x62,0x82,0x7C,0x02, //一朵花传来谁经过的温柔0x61,0x71,0x82,0x71,0x62,0xA2,0x71,0x76,//穿越千年的伤痛0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//只为求一个结果0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//你留下的轮廓指引我0x42,0x63,0x83,0x83,0x91,0x91,//黑夜中不寂寞0x61,0x71,0x82,0x71,0x62,0x0A2,0x71,0x76,//穿越千年的哀愁0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//是你在尽头等我0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//最美丽的感动会值得0x42,0x82,0x88,0x02,0x74,0x93,0x89,0xff//结束标志//用一生守候};uchar code jmszl[]={ //寂寞沙洲冷0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,//自你走后心憔悴0x21,0x31,0x51,0x52,0x31,0x52,0x61,0x15,0x14,//白色油桐风中纷飞0x51,0x52,0x31,0x52,0x62,0x13,0x11,0x13,0x32,0x28,0x08,0x28, //落花似人有情这个季节0x31,0x32,0x31,0x32,0x11,0x21,0x51,0x52,0x51,0x52,//河畔的风放肆拼命地吹0x51,0x51,0x31,0x32,0x31,0x32,0x81,0x72,0x63,//不断拨弄离人的眼泪0x62,0x71,0x81,0x72,0x61,0x61,0x52,0x31,0x21,0x32,0x51,0x54, //那样浓烈的爱再也无法给0x22,0x12,0x11,0x12,0x11,0x12,0x12,0x14,0x26,0x32,0x26,//伤感一夜一夜0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51, //当记忆的线缠绕过往支离破碎0x02,0x32,0x81,0x81,0x81,0x81,0x62,0x52,0x34,//是慌乱占据了心扉0x31,0x81,0x81,0x81,0x61,0x91,0x82,//有花儿伴着蝴蝶0x51,0x51,0x51,0x51,0x31,0x61,0x53,//孤雁可以双飞0x21,0x11,0x21,0x11,0x22,0x11,0x21,0x26,//夜深人静独徘徊0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,0 x52,//当幸福恋人寄来红色分享喜悦0x31,0x31,0x81,0x81,0x81,0x61,0x91,0x81,0x61,0x31,0x56,//闭上双眼难过头也不敢回0x32,0x32,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0 x51,0x34,//仍然捡尽寒枝不肯安歇微带着后悔0x21,0x31,0x51,0x31,0x21,0x11,0x61,0x21,0x16,//寂寞沙洲我该思念谁0xff};uchar code cuzhi[]={0xff,0xff,//占位0xFC,0x8E,//中央C调1-70xFC,0xED,0xFD,0x43,0xFD,0x6A,0xFD,0xB3,0xFD,0xF3,0xFE,0x2D,0xFE,0x47, //高八度1-70xFE,0x76,0xFE,0xA1,0xFE,0xC7,0xFE,0xD9,0xFE,0xF9,0xFF,0x16};ucharyinyue[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x0,0x0}; //将音调转化为对应的LED样式void delay1(uint z); //延时1MSvoid delay(uint z); //延时165MS,即十六分音符void song();void beep();//蜂鸣器叫一声main(){ uchar x;count1=0;//流水灯无花样count2=1;//唱第一首歌P30=0;//选取矩阵键盘的一列EA=1;//开总中断EX0=1;//开外部中断0IT0=1;//外部中断0下降沿触发方式EX1=1;//开外部中断1IT1=1;//外部中断1下降沿触发方式TMOD=0x01;//定时器0工作在方式1 TH0=0;TL0=0;ET0=1;while(1){if(count1!=0){switch(count1){case 1:for(x=0;x<14;x++) {duan=1;P1=huayang1[x]; beep();delay1(300); duan=0;if(count1!=1) break;}break;case 2:for(x=0;x<14;x++) {duan=1;P1=huayang2[x]; beep();delay1(300); duan=0;if(count1!=2) break;}break;case 3:for(x=0;x<16;x++) {duan=1;P1=huayang3[x]; beep();delay1(300); duan=0;if(count1!=3) break;}break;case 4:for(x=0;x<8;x++) {duan=1;P1=huayang4[x]; beep();delay1(300); duan=0;if(count1!=4) break;}break;}}else{song();delay1(1000);}}}void int0() interrupt 0 {EA=0;//关总中断delay1(1);//去抖if(key1==0){count2=0;//不让蜂鸣器唱歌TR0=0;count1++;if(count1==5)count1=1;}EA=1;//开总中断}void int1() interrupt 2 {EA=0;//关总中断delay1(1);//去抖if(key2==0){count1=0;//流水灯无花样TR0=1;i=0;//从头开始唱count2++;if(count2==3)count2=1;}EA=1;//开总中断}void timer0() interrupt 1 //用于产生各种音调{ TH0=timeh;TL0=timel;fm=~fm;}void song(){uint temp;uchar jp;//jp是简谱i=0;while(1){ if(count2==0){break;}if(count2==1) //选曲temp=qnzl[i];if(count2==2)temp=jmszl[i];if(temp==0xff)break;jp=temp/16; //取数的高4位duan=1;P1=yinyue[jp];duan=0;if(jp!=0){timeh=cuzhi[jp*2];timel=cuzhi[jp*2+1];}else{TR0=0;fm=1;//关蜂鸣器}delay(temp%16); //取数的低4位TR0=0; //唱完一个音停10MSfm=1;delay1(10);TR0=1;i++;}TR0=0;fm=1;}void delay(uint z) //延时165MS,即十六分音符{ uint x,y; for(x=z;x>0;x--)for(y=19000;y>0;y--);}void delay1(uint z) //延时1MS{ uint x,y;for(x=z;x>0;x--)for(y=112;y>0;y--);}void beep() //蜂鸣器叫一声{ uchar i;for(i=0;i<50;i++){ fm=~fm;delay1(1);}fm=1;}。
c语言编写的音乐播放器源代码)
include <windows.h> #include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>unsigned frequency[100];char hight[100];unsigned time[100];unsigned rate;void main(){voidset(unsignedf[],charh[],unsignedt[],int r,int num);void music(unsigned f[],unsigned t[],intnum);int flag=0;FILE *f1;int i,n,menu;char FileName[30];while(1){f1=NULL;i=n=0;printf("本程序采用编码的形式播放音乐。
\n");printf("\n用记事本编辑乐谱,然后通过输入文件名播放音乐\n");printf("乐谱文件可以自创,也可以抄别人的\n");printf("\n现在可以先输入数字再按回车播放音乐:\n");printf("1播放指定音乐music1\n");printf("2播放指定音乐music2\n");printf("3通过程序文件名播放音乐\n");printf("4退出\n");while(1){printf("menu=");scanf("%d",&menu);if(menu==1) {strcpy(FileName,"music1.txt");break;}if(menu==2){strcpy(FileName,"music2.txt");break;}if(menu==3){scanf("%s",FileName);break;}if(menu==4)exit(0);}printf("\n该文件的音乐编码如下:\n");if((f1=fopen(FileName,"r"))==NULL){ printf("不能打开文件!\n");exit(1);}fscanf(f1,"%d",&rate);while(!feof(f1)&&flag!=1){fscanf(f1," %d%c%d",&frequency[i],&hight[i],&time[i]);printf("%d%c%d",frequency[i],hight[i],time[i]);if(time[i]!=-1){i++;n++;}elseflag=1;}printf("\n");set(frequency,hight,time,rate,n);music(frequency,time,n);fclose(f1);}getch();}void set(unsigned f[],char h[],unsigned t[],int r,int num){int i,k;for(i=0;i<num;i++){t[i]=t[i]*r;switch(h[i]){case 'H':k=4;break;case 'M':k=2;break;case 'L':k=1;}switch(f[i]){case 1: f[i]=262*k; break;case 2: f[i]=296*k; break;case 3: f[i]=330*k; break;case 4: f[i]=349*k; break;case 5: f[i]=392*k; break; case 6: f[i]=440*k; break;case 7: f[i]=494*k; break;} }}voidmusic(unsignedf[],unsignedt[],intnum){int i;for(i=0;i<num;i++){Beep(f[i],t[i]);}。
安卓音乐播放器开发,含源代码
基于android平台的音乐播放器开发实验报告For personal use only in study and research; not for commercial use学生姓名:温从林学号:0215班级:计自1201第一章引言1.1 项目背景当今社会的生活节奏越来越快,人们对手机的要求也越来越高,由于手机市场发展迅速,使得手机操作系统也出现了不同各类,现在的市场上主要有三个手机操作系统,Windows mobile,symbian,以及谷歌的Android操作系统,其中占有开放源代码优势的Android系统有最大的发展前景。
那么能否在手机上拥有自己编写的个性音乐播放器呢?能的,谷歌Android系统就能做到。
本文的音乐播放器就是基于谷歌Android手机平台的播放器。
Android:是谷歌于2007年公布的开放式源代码手机系统,它的开放性就优于其它封闭式的手机系统,因此,任何人都可能根据自己的喜好将手机系统中的所有功能重新编写。
这使得越来越多的人关注这个操作系统。
本次作品音乐播放器就是基于Android平台的。
1.2 编写目的现今社会生活紧张,而欣赏音乐是其中最好的舒缓压力的方式之一,本项目的目的是开发一个可以播放主流音乐文件格式的播放器,本设计实现的主要功能是播放Mp3,Wav多种格式的音乐文件,并且能够控制播放,暂停,停止,播放列等基本播放控制功能,界面简明,操作简单。
本项目是一款基于Android手机平台的音乐播放器,使Android手机拥有个性的多媒体播放器,使手机显得更生动灵活化,与人们更为接近,让手机主人随时随地处于音乐视频的旋律之中。
使人们的生活更加多样化。
也使设计者更加熟练Android的技术和其它在市场上的特点。
1.3 开发环境Eclipse、Android SDK 3.2.0第二章系统需求分析2.1 功能需求(用例图分析)根据项目的目标,我们可获得项目系统的基本需求,以下从不同角度来描述系统的需求,并且使用用例图来描述,系统的功能需求,我们分成四部分来概括,即播放器的基本控制需要,播放列表管理需求,播放器友好性需求和播放器扩展卡需求。
利用Python编写本地音乐播放器
利⽤Python编写本地⾳乐播放器先上完整代码:修改⽂件夹路径即可运⾏# -*- encoding: utf-8 -*-'''@Description: :@Date :2022/03/24 17:43:26@Author :骤&⾬@version :1.0'''#导⼊相关库⽂件import osimport tkinterimport tkinter.filedialogimport randomimport timeimport threadingimport pygamefrom asyncio.base_tasks import _task_print_stackfrom cProfile import labelfrom email import headerfrom functools import total_orderingfrom importlib import find_loaderfrom logging import rootfrom mimetypes import initfrom re import Xfrom turtle import widthfrom matplotlib.pyplot import pausefrom scipy import rand#设置⽂件夹路径folder = r'C:\Users\Administrator\Desktop\Python\Python Code\TiquMusicFromVedio'"""@description : ⾳乐播放,默认播放⽂件夹内的所有mp3⽂件---------@param :-------@Returns :-------"""def play():global foldermusic =[folder+'\\'+music for music in os.listdir(folder)\if music.endswith(('.mp3','.wav','.ogg'))]total = len(music)#初始化混⾳器设备pygame.mixer.init()while playing:if not pygame.mixer.music.get_busy():#随机播放⼀⾸歌曲nextMusic = random.choice(music)pygame.mixer.music.load(nextMusic.encode())#播放⼀次pygame.mixer.music.play(1)musicName.set('playing.......'+nextMusic)else:time.sleep(0.3)root = ()root.title('⾳乐播放器')root.geometry('700x80+400+300')root.resizable(False,False)#关闭程序时执⾏的代码def closeWindow():global playingplaying = Falsetry:pygame.mixer.music.stop()pygame.mixer.quit()except:passroot.destroy()root.protocol('WM_DELETE_WINDOW',closeWindow)pause_resume=tkinter.StringVar(root,value = 'NotSet')playing = False#播放按钮def buttonPlayClick():global folderif not folder:folder = tkinter.filedialog.askdirectory()if not folder:returnglobal playingplaying = True#创建⼀个线程来播放⾳乐t = threading.Thread(target=play)t.start()#根据情况禁⽤或启⽤相应按钮buttonPlay['state'] = 'disabled'buttonStop['state'] = 'normal'buttonPause['state'] = 'normal'buttonNext['state'] = 'normal'pause_resume.set('Pause')buttonPlay = tkinter.Button(root,text = 'Play',command=buttonPlayClick)buttonPlay.place(x=20,y=10,width=50,height=20)#终⽌按钮def buttonStopClick():global playingplaying = Falsepygame.mixer.music.stop()musicName.set('暂时没有播放⾳乐')buttonPlay['state'] = 'normal'buttonStop['state'] = 'disabled'buttonPause['state'] = 'disabled'buttonStop = tkinter.Button(root,text='Stop',command=buttonStopClick)buttonStop.place(x=80,y=10,width=50,height=20)buttonStop['state']='disabled'#暂停与恢复复⽤按钮def buttonPauseClick():global playingif pause_resume.get()=='Pause':#playing = Falsepygame.mixer.music.pause()pause_resume.set('Resume')elif pause_resume.get()=='Resume':#playing = Truepygame.mixer.music.unpause()pause_resume.set('Pause')buttonPause = tkinter.Button(root,textvariable=pause_resume,command=buttonPauseClick) buttonPause.place(x=140,y=10,width=50,height=20)buttonPause['state']='disabled'#下⼀⾸def buttonNextClick():global playingplaying = Falsepygame.mixer.music.stop()pygame.mixer.quit()buttonPlayClick()buttonNext = tkinter.Button(root,text='Next',command=buttonNextClick)buttonNext.place(x=200,y=10,width=50,height=20)buttonNext['state']='disabled'musicName = tkinter.StringVar(root,value='暂时没有播放⾳乐!')labelName = bel(root,textvariable=musicName)labelName.place(x=0,y=40,width=700,height=20)#启动消息循环root.mainloop()运⾏结果如下:到此这篇关于利⽤Python编写本地⾳乐播放器的⽂章就介绍到这了,更多相关Python编写⾳乐播放器内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
音乐播放器程序源代码及注释:#include <reg52.h>#define uchar unsigned char#define uint unsigned intsbit duan=P2^6;sbit key1=P3^2;//按key1可切换花样sbit key2=P3^3;//按key2可切换歌曲sbit fm=P2^4;//蜂鸣器连续的IO口sbit P30=P3^0;//矩阵键盘的一列uchar code huayang1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf};//花样1uchar code huayang2[]={0x7f,0xfe,0xbf,0xfd,0xdf,0xfb,0xef,0xf7,0xef,0xfb,0xdf,0xfd,0xbf,0xfe};//花样2uchar code huayang3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff}; char code huayang4[]={ 0x55,0xaa,0xcc,0x33,0x99,0x66,0x0f,0xf0}; uchar count1;//花样标志uchar count2;//歌曲标志uchar timeh,timel,i;//编程规则:字节高位是简谱,低位是持续时间,//代表多少个十六分音符//1-7代表中央C调,8-E代表高八度,0代表停顿//最后的0是结束标志uchar code qnzl[]={ //千年之恋0x12,0x22,0x34,0x84,0x74,0x54,0x38,0x42,0x32,0x22,0x42,0x34,0x84,0 x72,0x82,0x94,0xA8,0x08,//前奏0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//竹林的灯火到过的沙漠0x32,0x31,0x21,0x32,0x82,0x71,0x81,0x71,0x51,0x32,0x22,//七色的国度不断飘逸风中0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//有一种神秘灰色的旋涡0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,//将我卷入了迷雾中0x63,0xA1,0xA2,0x62,0x92,0x82,0x52,//看不清的双手0x31,0x51,0x63,0x51,0x63,0x51,0x63,0x51,0x62,0x82,0x7C,0x02,//一朵花传来谁经过的温柔0x61,0x71,0x82,0x71,0x62,0xA2,0x71,0x76,//穿越千年的伤痛0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//只为求一个结果0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//你留下的轮廓指引我0x42,0x63,0x83,0x83,0x91,0x91,//黑夜中不寂寞0x61,0x71,0x82,0x71,0x62,0x0A2,0x71,0x76,//穿越千年的哀愁0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//是你在尽头等我0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//最美丽的感动会值得0x42,0x82,0x88,0x02,0x74,0x93,0x89,0xff//结束标志//用一生守候};uchar code jmszl[]={ //寂寞沙洲冷0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,//自你走后心憔悴0x21,0x31,0x51,0x52,0x31,0x52,0x61,0x15,0x14,//白色油桐风中纷飞0x51,0x52,0x31,0x52,0x62,0x13,0x11,0x13,0x32,0x28,0x08,0x28, //落花似人有情这个季节0x31,0x32,0x31,0x32,0x11,0x21,0x51,0x52,0x51,0x52,//河畔的风放肆拼命地吹0x51,0x51,0x31,0x32,0x31,0x32,0x81,0x72,0x63,//不断拨弄离人的眼泪0x62,0x71,0x81,0x72,0x61,0x61,0x52,0x31,0x21,0x32,0x51,0x54,//那样浓烈的爱再也无法给0x22,0x12,0x11,0x12,0x11,0x12,0x12,0x14,0x26,0x32,0x26,//伤感一夜一夜0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,//当记忆的线缠绕过往支离破碎0x02,0x32,0x81,0x81,0x81,0x81,0x62,0x52,0x34,//是慌乱占据了心扉0x31,0x81,0x81,0x81,0x61,0x91,0x82,//有花儿伴着蝴蝶0x51,0x51,0x51,0x51,0x31,0x61,0x53,//孤雁可以双飞0x21,0x11,0x21,0x11,0x22,0x11,0x21,0x26,//夜深人静独徘徊0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,0x52, //当幸福恋人寄来红色分享喜悦0x31,0x31,0x81,0x81,0x81,0x61,0x91,0x81,0x61,0x31,0x56,//闭上双眼难过头也不敢回0x32,0x32,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0x51, 0x34,//仍然捡尽寒枝不肯安歇微带着后悔0x21,0x31,0x51,0x31,0x21,0x11,0x61,0x21,0x16,//寂寞沙洲我该思念谁0xff};uchar code cuzhi[]={0xff,0xff,//占位0xFC,0x8E,//中央C调1-70xFC,0xED,0xFD,0x43,0xFD,0x6A,0xFD,0xB3,0xFD,0xF3,0xFE,0x2D,0xFE,0x47, //高八度1-70xFE,0x76,0xFE,0xA1,0xFE,0xC7,0xFE,0xD9,0xFE,0xF9,0xFF,0x16};uchar yinyue[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,0x0,0x0};//将音调转化为对应的LED样式void delay1(uint z); //延时1MSvoid delay(uint z); //延时165MS,即十六分音符void song();void beep();//蜂鸣器叫一声main(){ uchar x;count1=0;//流水灯无花样count2=1;//唱第一首歌P30=0;//选取矩阵键盘的一列EA=1;//开总中断EX0=1;//开外部中断0IT0=1;//外部中断0下降沿触发方式EX1=1;//开外部中断1IT1=1;//外部中断1下降沿触发方式TMOD=0x01;//定时器0工作在方式1TH0=0;TL0=0;ET0=1;while(1){if(count1!=0){switch(count1){case 1:for(x=0;x<14;x++){duan=1;P1=huayang1[x];beep();delay1(300);duan=0;if(count1!=1)break;}break;case 2:for(x=0;x<14;x++){duan=1;P1=huayang2[x];beep();delay1(300);duan=0;if(count1!=2)break;}break;case 3:for(x=0;x<16;x++){duan=1;P1=huayang3[x];beep();delay1(300);duan=0;if(count1!=3)break;}break;case 4:for(x=0;x<8;x++){duan=1;P1=huayang4[x];beep();delay1(300);duan=0;if(count1!=4)break;}break;}}else{song();delay1(1000);}}}void int0() interrupt 0{EA=0;//关总中断delay1(1);//去抖if(key1==0){count2=0;//不让蜂鸣器唱歌TR0=0;count1++;if(count1==5)count1=1;}EA=1;//开总中断}void int1() interrupt 2{EA=0;//关总中断delay1(1);//去抖if(key2==0){count1=0;//流水灯无花样TR0=1;i=0;//从头开始唱count2++;if(count2==3)count2=1;}EA=1;//开总中断}void timer0() interrupt 1 //用于产生各种音调{TH0=timeh;TL0=timel;fm=~fm;}void song(){uint temp;uchar jp;//jp是简谱i=0;while(1){ if(count2==0){break;}if(count2==1) //选曲temp=qnzl[i];if(count2==2)temp=jmszl[i];if(temp==0xff)break;jp=temp/16; //取数的高4位duan=1;P1=yinyue[jp];duan=0;if(jp!=0){timeh=cuzhi[jp*2];timel=cuzhi[jp*2+1];}else{TR0=0;fm=1;//关蜂鸣器}delay(temp%16); //取数的低4位TR0=0; //唱完一个音停10MS fm=1;delay1(10);TR0=1;i++;}TR0=0;fm=1;}void delay(uint z) //延时165MS,即十六分音符{ uint x,y;for(x=z;x>0;x--)for(y=19000;y>0;y--);}void delay1(uint z) //延时1MS{ uint x,y;for(x=z;x>0;x--)for(y=112;y>0;y--);}void beep() //蜂鸣器叫一声{ uchar i;for(i=0;i<50;i++){ fm=~fm;delay1(1);}fm=1; }。