一个音乐播放程序的编写
安卓音乐播放器开发含源代码

基于an droid平台的音乐播放器开发实验报告学生姓名:_______ 温从林 _________________学号: ___________________________________班级:计自1201 _____________第一章引言1.1项目背景当今社会的生活节奏越来越快,人们对手机的要求也越来越高,由于手机市场发展迅速,使得手机操作系统也出现了不同各类,现在的市场上主要有三个手机操作系统,Win dowsmobile,symbia n,以及谷歌的An droid操作系统,其中占有开放源代码优势的An droid系统有最大的发展前景。
那么能否在手机上拥有自己编写的个性音乐播放器呢?能的,谷歌An droid系统就能做到。
本文的音乐播放器就是基于谷歌An droid手机平台的播放器。
An droid :是谷歌于2007年公布的开放式源代码手机系统,它的开放性就优于其它封闭式的手机系统,因此,任何人都可能根据自己的喜好将手机系统中的所有功能重新编写。
这使得越来越多的人关注这个操作系统。
本次作品音乐播放器就是基于An droid平台的。
1.2编写目的现今社会生活紧张,而欣赏音乐是其中最好的舒缓压力的方式之一,本项目的目的是开发一个可以播放主流音乐文件格式的播放器,本设计实现的主要功能是播放Mp3 Wav多种格式的音乐文件,并且能够控制播放,暂停,停止,播放列等基本播放控制功能,界面简明,操作简单。
本项目是一款基于An droid手机平台的音乐播放器,使An droid手机拥有个性的多媒体播放器,使手机显得更生动灵活化,与人们更为接近,让手机主人随时随地处于音乐视频的旋律之中。
使人们的生活更加多样化。
也使设计者更加熟练An droid的技术和其它在市场上的特点。
1.3开发环境Eclipse、An droid SDK 320第二章系统需求分析2.1功能需求(用例图分析)根据项目的目标,我们可获得项目系统的基本需求,以下从不同角度来描述系统的需求,并且使用用例图来描述,系统的功能需求,我们分成四部分来概括,即播放器的基本控制需要,播放列表管理需求,播放器友好性需求和播放器扩展卡需求。
小程序音乐流程

小程序音乐流程小程序音乐流程随着智能手机的普及,人们越来越喜欢在手机上进行各种娱乐活动,其中之一就是听音乐。
小程序音乐流程就是为用户提供了一个方便快捷的音乐播放平台。
首先,用户需要下载安装一个支持小程序的软件,比如微信或者支付宝。
在软件中搜索并打开音乐小程序,进入音乐小程序的首页。
在首页中,用户可以看到推荐的热门歌单、新歌榜、排行榜等内容。
用户可以根据自己的喜好选择一个歌单,点击进入歌单页面。
在歌单页面中,用户可以看到该歌单包含的所有歌曲。
用户可以通过滑动屏幕来浏览歌曲列表,点击某个歌曲可以开始播放。
在播放界面中,用户可以看到歌曲的封面、歌名、歌手等信息。
用户可以通过点击播放按钮来开始播放歌曲,点击暂停按钮来暂停播放。
用户还可以通过滑动进度条来控制歌曲的播放进度。
除了播放音乐,小程序还提供了其他功能。
比如,用户可以选择单曲循环、列表循环或者随机播放歌曲。
用户还可以点击收藏按钮来收藏自己喜欢的歌曲,方便以后再次听到。
用户还可以点击分享按钮将自己喜欢的歌曲分享给朋友,让他们也可以听到这首歌曲。
在小程序中,用户还可以通过搜索来找到自己喜欢的歌曲。
在首页或者歌单页面中,用户可以点击搜索框进入搜索页面。
在搜索页面中,用户可以输入歌曲名、歌手名或者专辑名来搜索相关的歌曲。
搜索结果会显示在页面中,用户可以选择点击某个歌曲来进行播放。
除了搜索功能,小程序还提供了个人中心功能。
用户可以点击个人中心按钮进入个人中心页面,在该页面中可以看到自己的收藏歌曲、最近播放的歌曲等。
用户还可以点击设置按钮来进行个人设置,比如修改昵称、更换头像等。
总的来说,小程序音乐流程为用户提供了一个方便快捷的音乐播放平台。
用户可以通过小程序来搜索、播放自己喜欢的歌曲,并可以进行个人设置和收藏分享等操作。
小程序音乐流程的出现,方便了用户的音乐娱乐活动,提高了用户体验。
控制台C语言编写音乐播放器主要功能

#include "FM_Main.h"#include"CTL.H"#include<stdio.h>#include<windows.h>#include<mmsystem.h>#include"GUI.h"#include"ERR_CheckEnter.h"#pragma comment(lib,"winmm.lib")#include "FM_CheckFile.c"#include"FM_Choose.c"#include"FM_List.c"#include "FM_Path.c"int Order=1; //初始时为第一首歌,随音乐切换而切换--nextsong() int NewOrder=0;int Amount = 0; //歌曲总量int begin; //自定义列表中开始序号int circulatemode=1; //循环模式int pp=0;int begintemp=0; //存储自定义列表边界int ww=-1; // 显示自定义列表当前播放信息int upordown=1; //判断切歌方向int firstup=0;int originvolume=500; //默认音量为500char v[40]="setaudio aa volume to 500"; //初始化音量void Init(){Order=1;NewOrder=0;Amount = 0;circulatemode=1;pp=0;begintemp=0;ww=-1;upordown=1;firstup=0;originvolume=500;}void ShowFileList(){if(begintemp==0)begintemp=begin;Amount = FM_CheckFile();begin = Amount;if(NewOrder==0){Show_GUI_EIGHT();FM_CheckFilePrint(0,Amount);}else{Show_GUI_EIGHT();FM_CheckFilePrint(Amount,begintemp);}};void ShowFileDetails(){int i=0;if(upordown==1){if(NewOrder!=0){Order=Amount+1+ww;ww++;}}if(upordown==2){if(firstup==0){if(NewOrder!=0){Order=Amount+1+ww;ww--;}firstup--;}else{if(NewOrder!=0){Order=Amount+1+ww;ww--;}}}firstup+=4;i=Order-1;printf(" 正在播放的音乐\n");printf("-------------------------------------------------------\n");printf(" 歌曲号歌曲名歌手名\n");printf("-------------------------------------------------------\n");printf(" %3d ",info[i].ID);printf(" %-20s ",info[i].song);printf(" %-10s\n",info[i].singer);printf("-------------------------------------------------------\n");}void Play(){if(NewOrder!=0)Order=Amount+1;char vol[10]="500";char v[40];char ch[200];sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);sprintf(v," setaudio aa volume to %s",vol);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa repeat",NULL,0,NULL);// getchar();}void Stop(){mciSendString ("pause aa",NULL,0,NULL);printf("歌曲播放已暂停,输入3继续播放,输入12退出\n\n");// getchar();}void Resume(){mciSendString ("resume aa",NULL,0,NULL);// getchar();}void FastForward(){int n=1;int m=0;int d=0;int minute;int second;char dd[60][20];char temp[20];do{printf("输入1快进:");scanf("%d",&n);mciSendString ("status aa position", dd[m], 20, 0); char ch[20];sprintf(ch,"%s",dd[m]);d=atoi(dd[m]);d+=5000;minute=(int)(((int)(d/1000))/60);second=(d/1000)-minute*60;itoa(d,dd[m],10);sprintf(temp,"seek aa to %s",dd[m]);mciSendString (temp,NULL,0,NULL);Play();m++;clrscr();ShowFileList();ShowFileDetails();Show_GUI_FOUR();printf("当前时间:%d:%02d \n",minute,second);}while(n==1);}void FastBack(){int n=1;int m=0;int d=0;int minute;int second;char dd[60][20];char temp[20];do{printf("输入1快退");scanf("%d",&n);mciSendString ("status aa position", dd[m], 20, 0); char ch[20];sprintf(ch,"%s",dd[m]);d=atoi(dd[m]);d-=5000;minute=(int)(((int)(d/1000))/60);second=(d/1000)-minute*60;itoa(d,dd[m],10);sprintf(temp,"seek aa to %s",dd[m]);mciSendString (temp,NULL,0,NULL);Play();m++;clrscr();ShowFileList();ShowFileDetails();Show_GUI_FOUR();printf("当前时间:%d:%02d \n",minute,second);}while(n==1);}void StopStop(){char temp[20];char ch[10];itoa(0,ch,10);sprintf(temp,"seek aa to %s",ch);mciSendString (temp,NULL,0,NULL);mciSendString ("pause aa",NULL,0,NULL);printf("点击1重新播放\n\n");}void VolumePlus(){int n=1;// int originvolume=500;char volume[10];char temp[40];while(n==1){printf("输入1增加音量,输入2退出音量增加模式 ");scanf("%d",&n);originvolume+=250;itoa(originvolume,volume,10);sprintf(temp," setaudio aa volume to %s",volume);mciSendString (temp,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);getchar();clrscr();ShowFileList();ShowFileDetails();Show_GUI_FOUR();printf("当前音量:%d\n",originvolume);}originvolume-=250;}void VolumeReduce(){int n=1;// int originvolume=500;char volume[10];char temp[40];while(n==1){printf("输入1降低音量,输入2退出音量降低模式 ");scanf("%d",&n);originvolume-=250;itoa(originvolume,volume,10);sprintf(temp,"setaudio aa volume to %s",volume);mciSendString (temp,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();clrscr();ShowFileList();ShowFileDetails();Show_GUI_FOUR();printf("当前音量:%d\n",originvolume);}originvolume+=250;}void PreSong(){if(NewOrder==0){if(circulatemode==1){if(Order<1){Order=1;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}if(circulatemode==2){if(Order<1){Order=Amount;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}}else{Order=Amount+pp;if(circulatemode==1){if(Order<Amount){Order=Amount;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}if(circulatemode==2){if(Order<Amount){Order=begin;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}pp--;}upordown=2;}void NextSong(){if(NewOrder==0){if(circulatemode==1){if(Order>Amount){Order=Amount;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}if(circulatemode==2){if(Order>Amount)//////////////////////////////////////////////{Order=1;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order-1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}}else{Order=Amount+pp;if(circulatemode==1){if(Order<Amount)/////////////////////有问题{Order=Amount;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order+1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order+1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}if(circulatemode==2){if(Order<Amount)//有问题{Order=begin;char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order+1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[Order+1].add);mciSendString(ch,NULL,0,NULL);mciSendString(v,NULL,0,NULL);mciSendString("play aa ",NULL,0,NULL);// getchar();}}pp++;}upordown=1;}void SelectCirculMode(){int i=0;Show_GUI_SEVEN();scanf("%d",&i);if(i==1)circulatemode=1;if(i==2)circulatemode=2;}void SaveExit(){/*char dd[20];char log[50]={"testlog!!!"};mciSendString ("status aa position", dd, 20, 0);int d;d=atoi(dd);FILE *fp = NULL;fp = fopen("D:\\SaveLog.txt","a");fwrite(log,1,50,fp);*/}void PlayOperation(){int d;re: clrscr();ShowFileList();ShowFileDetails();Show_GUI_FOUR();printf("请选择要进行的操作:");epo:scanf("%d",&d);fflush(stdin);if(ERR_CheckEntero(d)){switch(d){case 1:Play();goto re;case 2:Stop();goto re;case 3:Resume();goto re;case 6:FastForward();goto re;case 8:FastBack();goto re;case 4:StopStop();goto re;case 9:VolumePlus();goto re;case 10:VolumeReduce();goto re;case 5:Order--;PreSong();goto re;case 7:Order++;NextSong();goto re;case 12:ChooseSong();goto re;case 11:SelectCirculMode();goto re;case 13:mciSendString("close aa", NULL, 0, NULL);return;case 14:SaveExit();// getchar();}}else{goto epo;}};void NewOperation(){ee: int i=0;printf("请选择要进行的操作:");scanf("%d",&i);fflush(stdin);switch(i){case 1:FM_CheckFilePrint(0,Amount);begin = FM_Choose(Amount,begin);break;case 2:begin = FM_Path(begin);break;case 3:break;default:printf("输入有误\n");goto ee;}};void ShowNewList(){FM_List(begin,Amount);NewOrder=Amount+1;PlayOperation();}void ChooseSong(){int id = 0;printf("请输入歌曲号:");scanf("%d",&id);if(id<1||id>Amount){printf("选择歌曲不存在!\n");}else{char ch[200];mciSendString("close aa", NULL, 0, NULL);sprintf(ch,"open \"%s\" alias aa",info[id-1].add);mciSendString(ch,NULL,0,NULL);mciSendString("play aa repeat",NULL,0,NULL);}}。
C#编的音乐播放器

C#音乐播放器设计一、音乐播放器的最终效果1. 整个播放器的主体最终效果如下:2. 经典模式如下:3. 音乐播放器设计已实现的基本功能:播放、暂停、播放列表、打开音乐文件、删除歌曲、添加歌曲、下一首、上一首、播放模式(顺序、循环、单曲循环、随机)、窗体最顶、经典模式、音量调节、歌曲播放进度控制、歌词同步、保存上次播放状态等等。
二、设计全部源代码1.主窗体(Form1)代码如下:using System;using System.Collections.Generic; using ponentModel; using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms; using System.Drawing.Imaging; using System.IO;namespace MusicPlayer{public partial class MMP : Form{public MMP(){InitializeComponent();}public int controlplay =-1;public Bitmap mplaycontrol = new Bitmap(@"play.bmp");public Bitmap mpausecontrol = new Bitmap(@"pause.bmp");public Bitmap mopenfile = new Bitmap(@"open.bmp");public Bitmap mprevious = new Bitmap(@"prev.bmp");public Bitmap mnext = new Bitmap(@"next.bmp");public Bitmap mstop = new Bitmap(@"stop.bmp");public Bitmap mmenu = new Bitmap(@"playlist_toolbar.bmp");public Boolean playcondition = false;public int preplaynum=0;Boolean p = false;Boolean fp = false;int x1, y1;Boolean yincan = false;Boolean mosttop = false;string ispaly;public int geci = 0;private void play_MouseMove(object sender, MouseEventArgs e){if (playcondition == false){Rectangle theRectangle = new Rectangle(new Point(113, 0), new Size(113, 48));play.Image = mplaycontrol.Clone(theRectangle, PixelFormat.DontCare);}else{Rectangle theRectangle = new Rectangle(new Point(113, 0), new Size(113, 48));play.Image = mpausecontrol.Clone(theRectangle, PixelFormat.DontCare);}}private void play_MouseLeave(object sender, EventArgs e){if (playcondition == false){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(113, 48));play.Image = mplaycontrol.Clone(theRectangle, PixelFormat.DontCare);}else{Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(113, 48));play.Image = mpausecontrol.Clone(theRectangle, PixelFormat.DontCare);}}private void openfile_MouseMove(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(60, 0), newSize(60, 48));openfile.Image = mopenfile.Clone(theRectangle,PixelFormat.DontCare);}private void openfile_MouseLeave(object sender, EventArgs e){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(60, 48));openfile.Image = mopenfile.Clone(theRectangle,PixelFormat.DontCare);}private void previous_MouseLeave(object sender, EventArgs e){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(83, 48));previous.Image = mprevious.Clone(theRectangle,PixelFormat.DontCare);}private void next_MouseMove(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(83, 0), newSize(83, 48));next.Image = mnext.Clone(theRectangle, PixelFormat.DontCare);}private void next_MouseLeave(object sender, EventArgs e){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(83, 48));next.Image = mnext.Clone(theRectangle, PixelFormat.DontCare);}private void stop_MouseMove(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(60, 0), newSize(60, 48));stop.Image = mstop.Clone(theRectangle, PixelFormat.DontCare);}private void previous_MouseMove(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(83, 0), newSize(83, 48));previous.Image = mprevious.Clone(theRectangle,PixelFormat.DontCare);}private void stop_MouseLeave(object sender, EventArgs e){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(60, 48));stop.Image = mstop.Clone(theRectangle, PixelFormat.DontCare);}private void play_Click(object sender, EventArgs e){}private void play_MouseDown(object sender, MouseEventArgs e){if (playcondition == false && playlist.Items .Count !=0){playcondition = true;musicplayer.Ctlcontrols.play();}else{playcondition = false;}}private void openfile_MouseDown(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(120, 0), new Size(60, 48));openfile.Image = mopenfile.Clone(theRectangle,PixelFormat.DontCare);}private void previous_MouseDown(object sender, MouseEventArgs e){if (playlist.Items.Count != 0){Rectangle theRectangle = new Rectangle(new Point(166, 0), new Size(83, 48));previous.Image = mprevious.Clone(theRectangle, PixelFormat.DontCare);musicplayer.Ctlcontrols.previous();if (preplaynum > 0){preplaynum = preplaynum - 1;playlist.SelectedIndex = preplaynum;}else{preplaynum = playlist.Items.Count - 1;playlist.SelectedIndex = preplaynum;}musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[preplaynum]);preplaynum = playlist.SelectedIndex;}}private void next_MouseDown(object sender, MouseEventArgs e){if (playlist.Items.Count != 0){Rectangle theRectangle = new Rectangle(new Point(166, 0), new Size(83, 48));next.Image = mnext.Clone(theRectangle, PixelFormat.DontCare);if (preplaynum < playlist.Items.Count - 1){preplaynum = preplaynum + 1;playlist.SelectedIndex = preplaynum;}else{preplaynum = 0;playlist.SelectedIndex =0;}musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[preplaynum]);}}private void stop_MouseDown(object sender, MouseEventArgs e){Rectangle theRectangle = new Rectangle(new Point(120, 0), new Size(60, 48));stop.Image = mstop.Clone(theRectangle, PixelFormat.DontCare);Rectangle Rectangle = new Rectangle(new Point(0, 0), new Size(113, 48));play.Image = mplaycontrol.Clone(Rectangle, PixelFormat.DontCare);playcondition = false;musicplayer.Ctlcontrols.stop();}private void openfile_Click(object sender, EventArgs e){openmusic.Multiselect = true;string musicname;string[] filepath;openmusic.Title = "打开音乐文件";openmusic .InitialDirectory="D:\\";openmusic.Filter = "mp3|*.mp3|wma|*.wma";openmusic.ShowDialog();filepath = openmusic.FileNames;int num = filepath.Length;for (int k = 0; k < num; k++){if (filepath[k] != ""){musicplayer.currentPlaylist.insertItem(musicplayer.currentPlaylist.count, musicplayer.newMedia(filepath[k]));musicname =musicplayer.currentPlaylist.Item[musicplayer.currentPlaylist.count - 1].name;int n = 0;for (int i = 0; i < playlist.Items.Count; i++){if (musicplayer.currentPlaylist.Item[i].name == musicname){n = 1;musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[i]);preplaynum = i;playlist.SelectedIndex = i;i = playlist.Items.Count;}}if (n == 0){playlist.Items.Add((playlist.Items.Count + 1) + "." + musicname);musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[musicplayer.curre ntPlaylist.count - 1]);playlist.SelectedIndex =playlist .Items .Count -1;preplaynum = preplaynum + 1;}else{musicplayer.currentPlaylist.removeItem(musicplayer.currentPlaylist.Item[musicplayer .currentPlaylist.count - 1]);}}}}private void listBox1_SelectedIndexChanged(object sender, EventArgs e){}private void playlist_SelectedIndexChanged(object sender, EventArgs e){}private void playlist_DoubleClick(object sender, EventArgs e){preplaynum = playlist.SelectedIndex;musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[playlist.SelectedIn dex]);}private void timer1_Tick(object sender, EventArgs e){if (musicplayer.currentPlaylist.count != 0) miname.Text = ;playtime.Text = "00:00";if (musicplayer.Ctlcontrols.currentPositionString != ""){playtime.Text = musicplayer.Ctlcontrols.currentPositionString;progressbar1.Width = Convert.ToInt16(progressbar.Width * musicplayer.Ctlcontrols.currentPosition / musicplayer.currentMedia.duration);progressbar1.Visible = true;}else{progressbar1.Visible = false;}}private void musicplayer_MediaCollectionAttributeStringChanged(object sender,AxWMPLib._WMPOCXEvents_MediaCollectionAttributeStringChangedEvent e) {}private void musicplayer_OpenStateChange(object sender,AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e){Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(113, 48));play.Image = mpausecontrol.Clone(theRectangle, PixelFormat.DontCare);playcondition = true;alltime.Text = musicplayer.currentMedia.durationString;}private void secondface_Click(object sender, EventArgs e){}private void musicplayer_Enter(object sender, EventArgs e){}private void MMP_Load(object sender, EventArgs e){this.Icon = notifyIcon1.Icon;panel1.BackColor = Color.Transparent;//不存在时创建文件,存在时追加文件StreamWriter sp = new StreamWriter("musicpath.txt", true, Encoding.UTF8);StreamWriter sn = new StreamWriter("musicname.txt", true, Encoding.UTF8);StreamWriter s = new StreamWriter("saveset.txt", true, Encoding.UTF8);sp.Close();sn.Close();s.Close();//打开文件,读取数据StreamReader swp = File.OpenText("musicpath.txt");StreamReader swn = File.OpenText("musicname.txt");StreamReader sw = File.OpenText("saveset.txt");string pathline;string nameline;string saveline;while ((pathline = swp.ReadLine()) != null&&(nameline =swn.ReadLine()) != null){if (File.Exists(pathline)){musicplayer.currentPlaylist.insertItem(musicplayer.currentPlaylist.count, musicplayer.newMedia(pathline));playlist.Items.Add(nameline);}}swn.Close();swp.Close();if (playlist.Items.Count < 1) miname.Text = "无任何曲目";int i=0;int r=192, g=192, b=0;//string[] save;//saveline = sw.ReadToEnd();//save=saveline.Split(' ');//MessageBox.Show(save[1].ToString ());while ((saveline = sw.ReadLine()) != null){switch (i){case 0:if (playlist.Items.Count > 0 && playlist.Items.Count > Convert.ToInt16(saveline))musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[Convert.ToInt16(s aveline)]);elsemusicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[0]);break ;case 1:ispaly = saveline;break ;case 2:r= Convert.ToInt32 (saveline );break;case 3:g = Convert.ToInt32(saveline);break;case 4:b = Convert.ToInt32(saveline);break;}i++;}sw.Close();playlist.BackColor = Color.FromArgb(r, g, b);addmusic.Image = mmenu.Clone(new Rectangle(new Point(0, 0), new Size(38, 26)), PixelFormat.DontCare);clearmusic.Image = mmenu.Clone(new Rectangle(new Point(38, 0), new Size(38, 26)), PixelFormat.DontCare);findmusic.Image = mmenu.Clone(new Rectangle(new Point(152, 0), new Size(38, 26)), PixelFormat.DontCare);hidelist.Image = mmenu.Clone(new Rectangle(new Point(76, 0), new Size(38, 26)), PixelFormat.DontCare);musicitem.Image = mmenu.Clone(new Rectangle(new Point(190, 0), new Size(38, 26)), PixelFormat.DontCare);playstyle.Image = mmenu.Clone(new Rectangle(new Point(228, 0), new Size(38, 26)), PixelFormat.DontCare);alltime.BackColor = Color.Transparent;progressbar1.Width = progressbar.Width;progressbar1.Height = progressbar.Height ;progressbar1.Left = progressbar.Left ;progressbar1.Top = progressbar.Top;allloop.Checked = true;oneloop.Checked = false;orderloop.Checked = false;randloop.Checked = false;timer3.Enabled = false;musicplayer.settings.setMode("loop", true);top.Image = new Bitmap(@"toph.jpg");voice.Value = 50;}private void progressbar_MouseDown(object sender, MouseEventArgs e){if (playtime.Text != "" && e.X!=0&&playlist .Items .Count !=0){progressbar1.Width = Convert.ToInt16(e.X);musicplayer.Ctlcontrols.currentPosition =musicplayer.currentMedia.duration * e.X / progressbar.Width;}}private void progressbar1_MouseDown(object sender, MouseEventArgs e){if (playtime.Text != "" && e.X != 0 && playlist.Items.Count != 0){progressbar1.Width = Convert.ToInt16(e.X);musicplayer.Ctlcontrols.currentPosition =musicplayer.currentMedia.duration * e.X / progressbar.Width;}}private void musicplayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e){}private void openmusic_FileOk(object sender, CancelEventArgs e){}private void next_Click(object sender, EventArgs e){}private void musicplayer_PlaylistChange(object sender,AxWMPLib._WMPOCXEvents_PlaylistChangeEvent e){}private void miname_TextChanged(object sender, EventArgs e){if (ispaly == "False"){musicplayer.Ctlcontrols.pause();Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(113, 48));play.Image = mplaycontrol.Clone(theRectangle, PixelFormat.DontCare);playcondition = false;ispaly = "True";}int index;string music;for (int i =0; i < playlist.Items.Count; i++){music = playlist.Items[i].ToString();index = music.IndexOf('.');if (music.Substring(index + 1, music.Length - 1 - index) == miname.Text){preplaynum = i;playlist.SelectedIndex =i;}}//}private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e){}private void minsize_Click(object sender, EventArgs e){this.WindowState =System.Windows.Forms.FormWindowState.Minimized;}private void exit_Click(object sender, EventArgs e){FileInfo musicpath = new FileInfo("musicpath.txt");FileInfo musicname = new FileInfo("musicname.txt");FileInfo saveset = new FileInfo("saveset.txt");StreamWriter swp =musicpath.CreateText();StreamWriter swn=musicname .CreateText();StreamWriter sw = saveset.CreateText();for (int i = 0; i < playlist.Items.Count; i++){swp.WriteLine(musicplayer .currentPlaylist .Item[i].sourceURL );swn.WriteLine(playlist.Items[i].ToString());}sw.WriteLine(preplaynum);sw.WriteLine(playcondition);sw.WriteLine(playlist.BackColor.R);sw.WriteLine(playlist.BackColor.G);sw.WriteLine(playlist.BackColor.B);swn.Close();swp.Close();sw.Close();Application.Exit();}private void toolStripMenuItem1_Click(object sender, EventArgs e){}private void toolStripMenuItem2_Click(object sender, EventArgs e){}private void panel1_Click(object sender, EventArgs e){addmusic.Visible = true;}private void toolStripMenuItem1_Click_1(object sender, EventArgs e){int n = playlist.SelectedIndex;if (n> -1){musicplayer.currentPlaylist.removeItem(musicplayer.currentPlaylist.Item[n]);}playlist.Items.Clear();for (int i = 0; i < musicplayer .currentPlaylist .count; i++){playlist.Items.Add ((i+1)+"."+musicplayer.currentPlaylist .Item [i].name );}if (playlist.Items.Count - 1 >= n){playlist.SelectedItem = playlist.Items[n];}else{playlist.SelectedItem = playlist.Items[n - 1];}}private void clearall_Click(object sender, EventArgs e){playlist.Items.Clear();musicplayer.currentPlaylist.clear();miname.Text = "无任何曲目";}private void orderloop_Click(object sender, EventArgs e){allloop.Checked =false ;oneloop.Checked = false;orderloop.Checked = true ;randloop.Checked = false;timer3.Enabled = false;musicplayer.settings.setMode("shuffle", false);}private void randloop_Click(object sender, EventArgs e){allloop.Checked = false ;oneloop.Checked = false;orderloop.Checked = false;randloop.Checked = true ;timer3.Enabled = false;musicplayer.settings.setMode("shuffle",true );}private void allloop_Click(object sender, EventArgs e){allloop.Checked =true ;oneloop.Checked = false;orderloop.Checked = false;randloop.Checked = false;timer3.Enabled = false ;musicplayer.settings.setMode("loop",true );}private void oneloop_Click(object sender, EventArgs e){allloop.Checked = false ;oneloop.Checked = true ;orderloop.Checked = false;randloop.Checked = false;timer3.Enabled = true;}private void mainface_Click(object sender, EventArgs e){}private void hidelist_Click(object sender, EventArgs e){if (yincan == false){this.Height = 255;yincan = true;}else{this.Height = 494;yincan = false;}}private void playlist_MouseDown(object sender, MouseEventArgs e) {}private void playlist_MouseMove(object sender, MouseEventArgs e) {private void playlist_MouseUp(object sender, MouseEventArgs e){}private void secondface_MouseMove(object sender, MouseEventArgs e) {if (e.X > playlist.Width + 1 && e.X < playlist.Width + 10){secondface.Cursor = System.Windows.Forms.Cursors.SizeWE;}elsesecondface.Cursor = System.Windows.Forms.Cursors.Default;if (p == true && e.X > 200 && e.X < 385){playlist.Width = e.X;}}private void secondface_MouseDown(object sender, MouseEventArgs e) {if (e.X > playlist.Width-5 && e.X < playlist.Width + 10){secondface.Cursor = System.Windows.Forms.Cursors.SizeWE;p = true;}}private void secondface_MouseUp(object sender, MouseEventArgs e) {secondface.Cursor = System.Windows.Forms.Cursors.Default;p = false;}private void MMP_MouseDown(object sender, MouseEventArgs e) {if (e.Y < 30){x1 = e.X;y1 = e.Y;fp = true;}private void MMP_MouseMove(object sender, MouseEventArgs e) {if (fp == true){this.Left = this.Left + e.X - x1;this.Top = this.Top + e.Y - y1;}}private void MMP_MouseUp(object sender, MouseEventArgs e){fp = false;}private void mainface_MouseDown(object sender, MouseEventArgs e) {if (e.Y < 30){x1 = e.X;y1 = e.Y;fp = true;}}private void mainface_MouseMove(object sender, MouseEventArgs e) {if (fp == true){this.Left = this.Left + e.X - x1;this.Top = this.Top + e.Y - y1;}}private void mainface_MouseUp(object sender, MouseEventArgs e) {fp = false;}private void hScrollBar1_Scroll(object sender, ScrollEventArgs e) {musicplayer.settings.volume = voice.Value;toolTip1.SetToolTip(voice, "音量" + voice.Value + "%");if (voice.Value == 0) toolTip1.SetToolTip(voice, "静音");}private void button1_Click(object sender, EventArgs e){}private void voice_Move(object sender, EventArgs e){}private void voice_MouseEnter(object sender, EventArgs e){voice.Cursor = System.Windows.Forms.Cursors.Hand;}private void voice_MouseHover(object sender, EventArgs e){toolTip1.SetToolTip(voice, "音量" + voice.Value + "%");if (voice.Value == 0) toolTip1.SetToolTip(voice, "静音");}private void progressbar_MouseMove(object sender, MouseEventArgs e) {}private void progressbar_MouseEnter(object sender, EventArgs e){toolTip1.SetToolTip(progressbar, "进度控制");progressbar.Cursor = System.Windows.Forms.Cursors.Hand;}private void play_MouseEnter(object sender, EventArgs e){play.Cursor = System.Windows.Forms.Cursors.Hand;if(playcondition ==false)toolTip1.SetToolTip(play , "播放");elsetoolTip1.SetToolTip(play, "暂停");}private void next_MouseEnter(object sender, EventArgs e){next.Cursor = System.Windows.Forms.Cursors.Hand;toolTip1.SetToolTip(next , "下一首");}private void stop_MouseEnter(object sender, EventArgs e){stop.Cursor = System.Windows.Forms.Cursors.Hand;toolTip1.SetToolTip(stop , "停止");}private void previous_MouseEnter(object sender, EventArgs e){previous.Cursor = System.Windows.Forms.Cursors.Hand;toolTip1.SetToolTip(previous , "上一首");}private void openfile_MouseEnter(object sender, EventArgs e){openfile.Cursor = System.Windows.Forms.Cursors.Hand;toolTip1.SetToolTip(openfile , "打开文件");}private void playstyle_MouseEnter(object sender, EventArgs e){}private void menuStrip1_MouseEnter(object sender, EventArgs e){menuStrip1.Cursor = System.Windows.Forms.Cursors.Hand;}private void menuStrip1_MouseMove(object sender, MouseEventArgs e) {}private void progressbar1_MouseEnter(object sender, EventArgs e){progressbar1.Cursor = System.Windows.Forms.Cursors.Hand;}private void button1_Click_1(object sender, EventArgs e){}private void changeface_Click(object sender, EventArgs e){}private void changcolor_Click(object sender, EventArgs e){colorDialog1.ShowDialog();playlist.BackColor = colorDialog1.Color;}private void pictureBox2_Click(object sender, EventArgs e){}private void notifyIcon1_Click(object sender, EventArgs e){this.WindowState =System.Windows.Forms.FormWindowState.Normal;}private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e){}private void minsize_MouseEnter(object sender, EventArgs e){toolTip1.SetToolTip(minsize, "最小化");}private void exit_MouseEnter(object sender, EventArgs e)toolTip1.SetToolTip(exit, "关闭");}private void top_MouseEnter(object sender, EventArgs e){if (this.TopMost ==false )toolTip1.SetToolTip(top , "置顶");elsetoolTip1.SetToolTip(top , "取消置顶");}private void top_MouseDown(object sender, MouseEventArgs e) {if (mosttop == false){mosttop = true;top.Image = new Bitmap(@"toph.jpg");this.TopMost = false;}else{mosttop = false;top.Image = new Bitmap(@"topz.jpg");this.TopMost = true;}}private void miname_Click(object sender, EventArgs e){}private void button1_Click_2(object sender, EventArgs e){progressbar1.BackColor = Color.FromArgb(20, 34, 120); }private void button1_Click_3(object sender, EventArgs e){}private void timer2_Tick(object sender, EventArgs e)if (controlplay == 1){playcondition = true;musicplayer.Ctlcontrols.play();controlplay = -1;}if (controlplay == 0){playcondition = false;musicplayer.Ctlcontrols.pause();controlplay = -1;}}private void button2_Click(object sender, EventArgs e){}private void pictureBox1_Click(object sender, EventArgs e){this.Hide();miniplayer secondform;secondform = new miniplayer(this );secondform.Show();}private void pictureBox1_MouseEnter(object sender, EventArgs e){toolTip1.SetToolTip(newstyle, "经典模式");}private void previous_Click(object sender, EventArgs e){}private void timer3_Tick(object sender, EventArgs e){if (musicplayer.Ctlcontrols.currentPosition >musicplayer.currentMedia.duration - 0.5)musicplayer.Ctlcontrols.playItem(musicplayer.currentPlaylist.Item[preplaynum]);private void button1_Click_4(object sender, EventArgs e){if (geci == 0){Form3 f3 = new Form3(this);f3.Show();geci = 1;}}private void button1_MouseEnter(object sender, EventArgs e){toolTip1.SetToolTip(button1, "显示歌词");}private void progressbar_Click(object sender, EventArgs e){}}}2.经典模式窗体(From2)代码如下:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Imaging;namespace MusicPlayer{public partial class miniplayer : Form{private MMP mainform;public miniplayer(MMP f){InitializeComponent();mainform = f;}Bitmap play_bmp = new Bitmap("play (2).bmp");Bitmap pause_bmp = new Bitmap("pause (2).bmp");Bitmap next_bmp = new Bitmap("next (2).bmp");Bitmap previous_bmp = new Bitmap("prev (2).bmp");Boolean a = false;int x1, y1;private void miniplayer_Load(object sender, EventArgs e){ //on.Left = under.Left;on.Top = under.Top;on.Width = under.Width;on.Height = under.Height;//if (mainform.TopMost == true) this.TopMost = true;if (mainform.playcondition == false)playbutton.Image = play_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);elseplaybutton.Image = pause_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);previousbutton.Image = previous_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);nextbutton.Image =next_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);}private void nextbutton_Click(object sender, EventArgs e){playbutton.Image = pause_bmp.Clone(new Rectangle(new Point(23, 0), new Size(23, 17)), PixelFormat.DontCare);}private void nextbutton_MouseEnter(object sender, EventArgs e){nextbutton.Image = next_bmp.Clone(new Rectangle(new Point(23, 0), new Size(23, 17)), PixelFormat.DontCare);}private void nextbutton_MouseLeave(object sender, EventArgs e){nextbutton.Image = next_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);}private void nextbutton_MouseUp(object sender, MouseEventArgs e){nextbutton.Image = next_bmp.Clone(new Rectangle(new Point(23, 0), new Size(23, 17)), PixelFormat.DontCare);}private void nextbutton_MouseDown(object sender, MouseEventArgs e){//if (mainform.playlist.Items.Count != 0){mainform.musicplayer.Ctlcontrols.next();if (mainform.preplaynum < mainform.playlist.Items.Count - 1){mainform.preplaynum = mainform.preplaynum + 1;mainform.playlist.SelectedItem =mainform.playlist.Items[mainform.preplaynum];}else{mainform.preplaynum = 0;mainform.playlist.SelectedItem =mainform.playlist.Items[0];}mainform.musicplayer.Ctlcontrols.playItem(mainform.musicplayer.currentPlaylist.Ite m[mainform.preplaynum]);}//nextbutton.Image = next_bmp.Clone(new Rectangle(new Point(46, 0), new Size(23, 17)), PixelFormat.DontCare);}private void previousbutton_MouseLeave(object sender, EventArgs e){previousbutton.Image = previous_bmp.Clone(new Rectangle(new Point(0, 0), new Size(23, 17)), PixelFormat.DontCare);}private void previousbutton_MouseEnter(object sender, EventArgs e){previousbutton.Image = previous_bmp.Clone(new Rectangle(new Point(23, 0), new Size(23, 17)), PixelFormat.DontCare);}private void previousbutton_MouseDown(object sender, MouseEventArgs e){//if (mainform.playlist.Items.Count != 0){mainform.musicplayer.Ctlcontrols.previous();if (mainform.preplaynum > 0){mainform.preplaynum = mainform.preplaynum - 1;mainform.playlist.SelectedItem =mainform.playlist.Items[mainform.preplaynum];}else{mainform.preplaynum = mainform.playlist.Items.Count - 1;mainform.playlist.SelectedItem =mainform.playlist.Items[mainform.preplaynum];}mainform.musicplayer.Ctlcontrols.playItem(mainform.musicplayer.currentPlaylist.Ite m[mainform.preplaynum]);。
单片机音乐播放器程序设计(DOC)

实验报告 51 单片机设计音乐播放器随着科技的发展,音乐播放功能随处都会用到,如,在开发儿童智力的玩具 中,等等。
目前单片机以其体积小、价格低、编程灵活等特点在这一领域独领风 骚。
、系统功能要求: 1、具有自动循环播放所有乐曲功能。
2、具有单独选择某首乐曲循环播放功能。
3、具有顺序查找乐曲循环播放功能。
4、具有停止播放功能。
二、系统整体方案提示:利用AT89S52产生乐曲音符,再把乐普翻译成计算机音乐语言,由单片机进 行信息处理,在经过信号放大,由喇叭放出乐曲声。
由于音符和节拍是由计算机 产生的,所以发音音符和节拍准确。
单独选择某首乐曲循环播放:按下 K4~K7键即可实现。
系统整体方案框图如下:利用 AT89C51产生乐曲音符,再把乐普翻译成绩 算计音乐语言,由单片机进行信息处理,在经过信号放大,由喇叭放出乐曲声。
由于音符和节拍是由计算机产生的,所以发音音符和节拍准确。
整体框图如图 图一所示。
1、 循环播放:按下 K1 键即可实现。
2、 顺序查找乐曲循环播放:按下 K2键即可实现。
3、 停止播放:按下K3键即可实现。
4、三、硬件系统原理图: 硬件系统原理图如下页图:1)单片机:选择 AT89S52,由于AT89S52是一个低电压,高性能 CMOS 位单 片机,内含4k bytes 的可反复擦鞋的制度程序存储器(PERO )和128bytes 的随机存取数据存储器(RAM ,器件采用ATME 公司的高密度、非易失性存 储技术生产,兼容标准MC — 51指令系统,片内置通用8位中央处理器和Flash 存储单元,内置功能强大的微型计算机 AT89S52提供了高性价比的解决方案。
其内部有足够本系统对存储器的要求,不用外扩。
2)按键控制电路:如图由P1 口作为输入,构成矩阵式按键接口方式。
3)输出控制:此部分的放大电路简单容易实现。
主要采用了一个小功率PNP 型硅管9012,利用“分压偏置式工作点稳定直 流通路”,达到了对静态工作点的稳定。
安卓音乐播放器实现代码

1. Mp3Player.java 文件package com.jacky.multimedia;import java.io.File;import java.io.FilenameFilter;import java.io.IOException;import java.util.ArrayList;import java.util.List;import android.app.ListActivity;import android.media.MediaPlayer;import android.media.MediaPlayer.OnCompletionListener;import android.os.Bundle;import android.os.Handler;import android.view.KeyEvent;import android.view.View;import android.widget.ArrayAdapter;import android.widget.ImageButton;import android.widget.ListView;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class Mp3Player extends ListActivity {/** Called when the activity is first created. *//* 定义5个图像按钮*/private ImageButton mFrontImageButton = null;private ImageButton mStartImageButton = null;private ImageButton mPauseImageButton = null;private ImageButton mStopImageButton = null;private ImageButton mNextImageButton = null;/*定义进度handler,显示百分比进度*/Handler mPercentHandler = new Handler();/*定义拖动条*/private SeekBar mSeekBar=null;/*定义显示文本框*/private TextView curProgressText=null;private TextView curtimeAndTotaltime=null;/* 定于一个多媒体对象*/public MediaPlayer mMediaPlayer = null;/*定于一个数据播放列表,用来存放从指定文件中搜索到的文件*/private List<String> mMusicList = new ArrayList<String>();/* 定义在播放列表中的当前选择项*/private int currentListItme = 0;/*定义要播放的文件夹路径*/private static final String MUSIC_PATH = new String("/mnt/sdcard/");/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(yout.main);/* 更新播放列表*/musicList();/*初始化多媒体对象*/mMediaPlayer = new MediaPlayer();/*初始化图像按钮*/mFrontImageButton = (ImageButton) findViewById(stImageButton); mStopImageButton = (ImageButton) findViewById(R.id.StopImageButton); mStartImageButton = (ImageButton) findViewById(R.id.StartImageButton); mPauseImageButton = (ImageButton) findViewById(R.id.PauseImageButton); mNextImageButton = (ImageButton) findViewById(R.id.NextImageButton);/*初始化拖动条和当前进度显示值*/mSeekBar=(SeekBar)findViewById(R.id.SeekBar01);curProgressText=(TextView)findViewById(R.id.currentProgress); curtimeAndTotaltime=(TextView)findViewById(R.id.curtimeandtotaltime);/*监听停止按钮*/mStopImageButton.setOnClickListener(new ImageButton.OnClickListener() {@Overridepublic void onClick(View v){/*判断是否正在播放歌曲*/if (mMediaPlayer.isPlaying()){/*如果在播放歌曲时,按下开始按钮,则重开开始播放*/mMediaPlayer.reset();}}});/*监听开始按钮*/mStartImageButton.setOnClickListener(new ImageButton.OnClickListener(){@Overridepublic void onClick(View v){ /*播放当前选择歌曲,通过listView列表中onListItemClick方法得到选择的时第几项*/playMusic(MUSIC_PATH + mMusicList.get(currentListItme));/*开始播放歌曲时,同步进行更新拖动条进度*/startSeekBarUpdate();}});/*监听暂停按钮*/mPauseImageButton.setOnClickListener(new ImageButton.OnClickListener(){public void onClick(View view){if (mMediaPlayer.isPlaying()){/*如果有播放歌曲,暂停*/mMediaPlayer.pause();}else{/*如果没有播放歌曲,则开始播放*/mMediaPlayer.start();}}});/*监听下一首按钮*/mNextImageButton.setOnClickListener(new ImageButton.OnClickListener(){@Overridepublic void onClick(View arg0){nextMusic();}/*监听上一首按钮*/mFrontImageButton.setOnClickListener(new ImageButton.OnClickListener() {@Overridepublic void onClick(View arg0){FrontMusic();}});/*监听拖动条*/mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub/*如果拖动进度发生改变,则显示当前进度值*/curProgressText.setText("当前进度: "+progress);}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubcurProgressText.setText("拖动中...");}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stubint dest = seekBar.getProgress();int mMax = mMediaPlayer.getDuration();int sMax = mSeekBar.getMax();mMediaPlayer.seekTo(mMax*dest/sMax);}});}/*按键处理时间,当按下返回按键时的处理方法*/public boolean onKeyDown(int keyCode, KeyEvent event){if ( keyCode == KeyEvent.KEYCODE_BACK){mMediaPlayer.stop();mMediaPlayer.release();this.finish();return true;}return super.onKeyDown(keyCode, event);}/*ListView选择项监听方法,即当前鼠标在列表中选择的第几项*/protected void onListItemClick(ListView l, View v, int position, long id){currentListItme = position;playMusic(MUSIC_PATH + mMusicList.get(position));}/*更新播放列表*/public void musicList(){/*从指定的路径中读取文件,并与播放列表关联*/File home = new File(MUSIC_PATH);/*读取指定类型的文件,在本程序,指定播放类型为mp3*/if (home.listFiles(new MusicFilter()).length > 0){/*读取文件*/for (File file : home.listFiles(new MusicFilter())){mMusicList.add(file.getName());}/*播放文件与播放列表关联*/ArrayAdapter<String> musicList = new ArrayAdapter<String>(Mp3Player.this,yout.musicitme, mMusicList); setListAdapter(musicList);}}/*播放指定路径中的音乐*/private void playMusic(String path){{/* 重置多媒体*/mMediaPlayer.reset();/*读取mp3文件*/mMediaPlayer.setDataSource(path);/*准备播放*/mMediaPlayer.prepare();/*开始播放*/mMediaPlayer.start();/*监听播放是否完成*/mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {public void onCompletion(MediaPlayer arg0){/*播放完当前歌曲,自动播放下一首*/nextMusic();}});}catch (IOException e){}}/*播放下一首*/private void nextMusic(){if (++currentListItme >= mMusicList.size()){currentListItme = 0;}else{playMusic(MUSIC_PATH + mMusicList.get(currentListItme));}}/*播放上一首歌曲*/private void FrontMusic(){if (--currentListItme >= 0){currentListItme = 0;}{playMusic(MUSIC_PATH + mMusicList.get(currentListItme));}}/*更新拖动条进度*/public void startSeekBarUpdate(){mPercentHandler.post(start);}Runnable start=new Runnable(){@Overridepublic void run() {// TODO Auto-generated method stubmPercentHandler.post(updatesb);//用一个handler更新SeekBar}};Runnable updatesb =new Runnable(){@Overridepublic void run() {// TODO Auto-generated method stubint position = mMediaPlayer.getCurrentPosition();int mMax = mMediaPlayer.getDuration();int sMax = mSeekBar.getMax();mSeekBar.setProgress(position*sMax/mMax);curtimeAndTotaltime.setT ext("当前播放时间:"+position/1000+"秒"+"\n歌曲总时间: "+mMax/1000+"秒");mPercentHandler.postDelayed(updatesb, 1000);//每秒钟更新一次}};}/*播放文件选择类*/class MusicFilter implements FilenameFilter{public boolean accept(File dir, String name){/*指定扩展名类型*/return (name.endsWith(".mp3"));}}2.main.xls文件<?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutxmlns:android="/apk/res/android" android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ListViewandroid:id="@id/android:list"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:drawSelectorOnT op="false"/><ImageButtonandroid:id="@+id/LastImageButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="10px"android:layout_y="70px"android:src="@drawable/last"/><ImageButtonandroid:id="@+id/StopImageButton"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_x="70px"android:layout_y="70px"android:src="@drawable/stop"/><ImageButtonandroid:id="@+id/StartImageButton"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_x="130px"android:layout_y="70px"android:src="@drawable/start"/><ImageButtonandroid:id="@+id/PauseImageButton"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_x="190px"android:layout_y="70px"android:src="@drawable/pause"/><ImageButtonandroid:id="@+id/NextImageButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="250px"android:layout_y="70px"android:src="@drawable/next"/><SeekBar android:id="@+id/SeekBar01"android:layout_height="wrap_content"android:layout_x="0dp"android:layout_y="200dp"android:layout_width="fill_parent"android:max="100"android:progress="0"android:secondaryProgress="50"android:visibility="visible"></SeekBar><TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_y="250dp" android:id="@+id/currentProgress"></TextView><TextView android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_y="300dp" android:id="@+id/curtimeandtotaltime"></TextView></AbsoluteLayout>3.musictime.xls<?xml version="1.0" encoding="utf-8"?><TextView xmlns:android="/apk/res/android" android:id="@+id/T extView01"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"/>4.AndroidManifest.xls<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="/apk/res/android" package="com.jacky.multimedia"android:versionCode="1"android:versionName="1.0"><application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".Mp3Player"android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="UNCHER" /></intent-filter></activity></application><uses-sdk android:minSdkVersion="3" /></manifest>。
一个简单的音乐播放器的java代码

import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.media.bean.playerbean.*;import java.io.IOException;import javax.swing.JOptionPane;import java.awt.*;public class lyt extends JFrame implements Runnable { public MediaPlayer soumd1;private JButton playSound, stopsound, tjian,loopSound; private JMenuItem jmiOpen,jmiSave,jmiExit,jmiAbout; public JPanel jp1, jp2, jp3, jp4;public JList jl;private JButton last, next, stop;public Vector vector, mingcheng;boolean fo = false, geshi = false;JLabel jl1, jl2, sj1, sj2;JTextField jt1, jt2;int a = 0, b = 0, you = 1, mm = 0;public lyt() {super("200842018java音乐播放器");soumd1 = new MediaPlayer();Container c = getContentPane();c.setLayout(new FlowLayout());mingcheng = new Vector();jp1 = new JPanel();c.add(jp1);JMenuBar mb=new JMenuBar();setJMenuBar(mb);JMenu JMenu("文件");mb.add();JMenu helpMenu=new JMenu("帮助");mb.add(helpMenu);(jmiOpen=new JMenuItem("打开"));(jmiSave=new JMenuItem("播放"));helpMenu.add(jmiAbout=new JMenuItem("关于"));JPanel jp2 = new JPanel();jp2.setLayout(new FlowLayout());jp2.add(last = new JButton("后退"));jp2.add(playSound = new JButton("播放"));jp2.add(tjian = new JButton("添加"));jp2.add(next = new JButton("前进"));jp2.add(stopsound = new JButton("停止"));jp2.add(loopSound= new JButton("循环"));getContentPane().add(jp2, BorderLayout.SOUTH);jp2 = new JPanel();jp2.add(playSound);jp2.add(stopsound);c.add(jp2);jp4 = new JPanel();sj1 = new JLabel();sj2 = new JLabel();jp4.add(sj1);jp4.add(sj2);c.add(jp4);vector = new Vector();jl = new JList(mingcheng);jl.setVisibleRowCount(4);jl.setFixedCellHeight(30);jl.setFixedCellWidth(265);jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;c.add(new JScrollPane(jl));jp3 = new JPanel();jp3.add(tjian);c.add(jp3);try {String s = "d:\\music.txt";ObjectInputStream input = new ObjectInputStream( new (s));lujin a1 = (lujin) input.readObject();mingcheng = a1.b;vector = a1.a;jl.setListData(mingcheng);}catch (Exception e) {System.out.println("D盘没有保存音乐文件");}jmiOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) {J = new J();.set(J);(new File("."));.set(newjavax.swing.() {public boolean accept() {String name = ().toLowerCase();return name.endsWith(".mp3")|| ();}public String getDescription() {return "音乐文件(*.mp3)";}});if ((lyt.this) ==J) {String =().getAbsolutePath();vector.add();StringBuffer buffer = daoxu();mingcheng.add(buffer);}}});tjian.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent event) {J = new J();.set(J);(newFile("."));.set(newjavax.swing.() {public boolean accept() {String name =().toLowerCase();return name.endsWith(".mp3")|| ();}public String getDescription() {return "音乐文件(*.mp3)";}});if ((lyt.this) ==J) {String =().getAbsolutePath();vector.add();StringBuffer buffer = daoxu();mingcheng.add(buffer);}}});jmiSave.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());= new );if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") || yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException eee) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});loopSound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String) vector.get(jl.getSelectedIndex());= new );if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3")|| yy.matches("[\\S\\s]*.MP3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi=true;try {Thread.sleep(500);} catch (InterruptedException we) {}} elseJOptionPane.showMessageDialog(null,"不支持此格式,无法播放");} elseJOptionPane.showMessageDialog(null,"此歌曲文件已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});playSound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());= new );if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") ||yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException eee) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});stopsound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {a = 0;b = 0;you = 0;mm = 0;geshi = false;fo = false;sj1.setText(null);sj2.setText(null);if (jl.getSelectedIndex() >= 0)soumd1.stop();}});jl.addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent event) {if (event.getClickCount() == 2) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());= new );if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") ||yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException e) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}}if (event.isMetaDown()) {if (jl.getSelectedIndex() >= 0) {int a = jl.getSelectedIndex();jt1.setText(mingcheng.get(jl.getSelectedIndex()) + "");jt2.setText(vector.get(jl.getSelectedIndex()) + "");}}}});addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {String s = "d:\\music.txt";mmm(vector, mingcheng, s);System.exit(0);}});setSize(370, 270);setVisible(true);}public void run() {while (true) {Date now = new Date();try {Thread.sleep(1000);}catch (InterruptedException e) {}if (geshi) {you = (int) soumd1.getMediaTime().getSeconds();mm = you % 60;if (you != 0)if (you % 60 == 0) {b++;}sj1.setText(b + ":" + mm);}}}public StringBuffer daoxu(String ) {String mc = "";for (int i = (); i >= 1; i--) {if ((i - 1) == '\\')break;mc += (i - 1);}StringBuffer buffer = new StringBuffer(mc);StringBuffer mm = buffer.reverse();return mm;}public void mmm(Vector vector, Vector mingcheng, String lujin) {lujin a = new lujin(vector, mingcheng);try {ObjectOutputStream output = new ObjectOutputStream(new (lujin));output.writeObject(a);output.flush();output.close();}catch (Exception e) {}}public static void main(String agrs[]) {lyt s = new lyt();Thread t1 = new Thread(s);t1.start();s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }class lujinimplements Serializable {Vector a = new Vector();Vector b = new Vector();public lujin(Vector vector, Vector mingcheng) {a = vector;b = mingcheng;}}}。
用单片机制作简单音乐播放器代码

if(k==6) return 0xdf; if(k==7) return 0xbf; if(k>=8) return 0x7f; }
uint temp;
uchar jp;//jp 是简谱 //用于产生各种音调 j=0; while(!RI) {
temp=happynewyear[j]; jp=temp/16; //取数的高 4 位 P1=light(jp); if(jp!=0) {
timeh=cuzhi[jp*2]; timel=cuzhi[jp*2+1]; } else {
void main () {
TMOD=0x21; TH1=0xfd; TL1=0xfd; TR1=1; REN=1; SM0=0; SM1=1; while(1) {
if(RI==1) {
RI=0; a=SBUF; if (a==1) {
main1(); EA=0; TR0=0;
} if(a==2) {
ET0=1; song2();
} void song2() {
uint temp;
uchar jp;//jp 是简谱 //用于产生各种音调 j=0; while(!RI) {
temp=wnyhln[k]; jp=temp/16; //取数的高 4 位 P1=light(jp); //LED 灯伴随音调的变化而闪烁 if(jp!=0) {
} void song3() {
uint temp;
uchar jp;//jp 是简谱 //用于产生各种音调 j=0; while(!RI) {
temp=ysysljj[h]; jp=temp/16; //取数的高 4 位 P1=light(jp); if(jp!=0) {
基于QT的音乐播放器编程(实现最基本的功能)

第一节实现基本功能说明:源代码我已经上传到CSDN网站,请大家到网站搜索“基于QT的音乐播放器源代码及详细教程”下载。
1.新建工程,基类选择Qwidget。
双击打开界面文件,在界面文件中创建label显示时间、若干个toolbutton按钮和一个listWidget列表显示歌曲列表。
点击“文件”->“新建”创建QT资源文件,在工程目录下建文件夹“images”,双击QT资源文件添加前缀“/”,再添加图标文件。
2.单击上一曲按钮,在属性栏设置标题tooltip和图标icon:界面如下:3.右键几个按钮,转入槽函数,列表和歌词的信号选择clicked(bool)。
4.工程文件中添加语句QT+=phonon对音乐播放器进行设计,主要用到模块中的MediaObject(管理媒体源)AudioOutput(连接物理设备)SeekSlider(实现进度条)QList(实现播放列表)大概地说,Phonon的工作机制是使用MediaObject来管理MediaSource即源文件,通过Path连接到AudioOutput,最后是由AudioOutput5.修改widget.h头文件在widget.h头文件添加语句:#include<phonon>在头文件声明变量:private:Phonon::MediaObject*audio;//QAction*stop;QAction*open;QAction*sound;QAction*exit;QAction*remove;头文件声明函数:public:void creatActions();//创建动作6.修改widget.cpp文件构造函数添加:this->setWindowTitle(tr("音乐播放器"));//设置标题/**初始化媒体**/audio=new Phonon::MediaObject();//媒体对象audio->setTickInterval(1);audioOutput=new Phonon::AudioOutput(Phonon::VideoCategory);//音频输出Phonon::createPath(audio,audioOutput);//连接媒体对象与音频输出musicInformationMediaObject=new Phonon::MediaObject(this);//音乐信息对象volumeSlider=new Phonon::VolumeSlider(audioOutput,this);//音量滑动条volumeSlider->move(190,100);volumeSlider->resize(50,20);volumeSlider->setStyleSheet("background-color:rgb(255,255,255,100)"); volumeSlider->setFixedWidth(100);//固定音量条大小seekSlider=new Phonon::SeekSlider(audio,this);//进度滑动条seekSlider->move(10,35);seekSlider->resize(170,20);seekSlider->setStyleSheet("background-color:rgb(255,255,255,100)");creatActions();函数定义://播放/暂停void Widget::on_toolButton_playpause_clicked(){if(sourceList.isEmpty()){return;}audio->setQueue(sourceList);//if{}}//{audio->stop();}void Widget::on_toolButton_open_clicked(){QStringList files=QFileDialog::getOpenFileNames(this,tr("SelecFilestoplay"));//使用QFileDialog的getOpenFileNames方法获取若干个音乐文件,QString file;foreach(file,files)//使用Qt中的foreach遍历每个选中的文件,将其添加到播放列表中。
用单片机制作简单音乐播放器代码

} void song3() {
uint temp;
uchar jp;//jp 是简谱 //用于产生各种音调 j=0; while(!RI) {
temp=ysysljj[h]; jp=temp/16; //取数的高 4 位 P1=light(jp); if(jp!=0) {
timeh=cuzhi[jp*2]; timel=cuzhi[jp*2+1]; } else { TR0=0; fm=1;//关蜂鸣器 } delay2(temp%16); //取数的低 4 位 TR0=0; //唱完一个音停 30MS fm=1; P1=0xff; delay(30); TR0=1; h++; if(h==44) h=0; }
write_data(table5[num]); delay(20); } EA=1;//开总中断 EX0=1;//开外部中断 IT0=1;//外部中断 0 下降沿触发方式 EX1=1;//开外部中断 1 IT1=1;//外部中断 1 下降沿触发方式 TH0=0; TL0=0; ET0=1; song3();
ET0=1; song2();
} void song2() {
uint temp;
uchar jp;//jp 是简谱 //用于产生各种音调 j=0; while(!RI) {
temp=wnyhln[k]; jp=temp/16; //取数的高 4 位 P1=light(jp); //LED 灯伴随音调的变化而闪烁 if(jp!=0) {
};
uchar code cuzhi[]={
0xFF,0xFF,//占位 0xFC,0x8E,//中央 C 调 1-7
单片机蜂鸣器音乐代码

单片机蜂鸣器音乐代码在单片机的应用中,蜂鸣器是一个常用的音频输出设备。
它可以通过产生不同频率的声音来实现音乐播放、提醒和警报等功能。
本文将介绍如何使用单片机控制蜂鸣器播放音乐,并提供一个简单的音乐代码示例。
首先,让我们了解一下单片机蜂鸣器的工作原理。
蜂鸣器实际上是一个压电陶瓷元件,当电压作用于其上时,它会振动产生声音。
为了产生不同的音调,我们需要控制蜂鸣器的频率和占空比。
单片机通过IO口与蜂鸣器连接,并使用定时器来产生所需的频率。
具体的代码实现将依赖于使用的单片机型号和开发环境。
在这里,我们将以C语言为例,并基于51单片机进行说明。
以下是一个简单的单片机蜂鸣器音乐代码示例,演奏的是《欢乐颂》的前几个音符:```c#include <reg52.h>// 定义各个音符的频率#define C4 4778#define D4 4257#define E4 3792#define F4 3579#define G4 3189#define A4 2841#define B4 2531#define C5 2388// 延时函数void delay(unsigned int count){while(count--);}// 发声函数void beep(unsigned int frequency, unsigned int duration) {unsigned int i;unsigned long time;time = 11059200 / frequency; time >>= 1;for(i = 0; i < duration; i++) {P1 = 0x08;delay(time);P1 = 0x00;delay(time);}}// 主函数void main(){// 设置定时器TMOD = 0x01;TH0 = (65536 - 50000) / 256; TL0 = (65536 - 50000) % 256; TR0 = 1;// 播放音乐beep(C4, 100);beep(D4, 100);beep(E4, 100);beep(F4, 100);beep(G4, 100);beep(A4, 100);beep(B4, 100);beep(C5, 100);while(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总结:本音乐播放器的界面还可以设计的更加漂亮好看,这个就得发挥你的界面设计能力咯!以上播放器的设计还有很多可以改善的地方,比如代码能否更加简化?还缺少哪些功能?如何更加赏心悦目?这些就交给你自己去完善咯!另外,为了方便有兴趣的人更好的理解整个设计过程,我已共享该音乐播放器程序设计的整个工程文件(本程序用到的图片也含有)到以下网址:可以下载看看,希望对你有所帮助!。
控制台C语言编写音乐播放器主要功能

控制台C语言编写音乐播放器主要功能音乐播放器是一种可以播放音乐文件的应用程序,具有多种功能来帮助用户管理和播放音乐。
下面是控制台C语言编写音乐播放器的主要功能:1.音乐:用户可以通过输入歌曲名或艺术家来他们想要播放的音乐。
功能也可以根据关键词进行过滤和排序。
2.音乐播放:一旦用户找到他们想要听的歌曲,他们可以选择播放它。
音乐播放器应该能够打开并解码音乐文件,然后通过音频设备播放音乐。
4.歌曲信息显示:在播放音乐的同时,音乐播放器应该显示歌曲的相关信息,如歌曲名、艺术家、专辑名、歌词等。
这些信息可以从音乐文件的元数据中获取。
5.音乐控制:音乐播放器应该具有基本的音乐控制功能,如播放、暂停、停止、上一首、下一首等。
用户可以通过命令来控制音乐的播放状态。
6.音量控制:用户可以通过增加或减少音量来调整音乐的音量。
音乐播放器应该能够调整音频设备的输出音量。
7.重复和随机播放:用户可以选择歌曲的播放模式,如顺序播放、循环播放、随机播放等。
音乐播放器应该能够根据用户的选择来调整播放模式。
9.用户界面:音乐播放器应该有一个简洁而直观的用户界面,允许用户轻松地浏览、和管理自己的音乐。
用户界面可以使用控制台界面或基于文本的界面。
10.错误处理:音乐播放器应该能够处理各种错误情况,如无效的输入、文件不存在、解码错误等。
它应该能够向用户显示有关错误的信息,并采取适当的措施来避免应用程序崩溃。
11.文件格式支持:音乐播放器应该支持多种常见的音乐文件格式,如MP3、WAV、FLAC等。
它应该能够根据文件格式选择合适的解码器。
12.常规设置:音乐播放器应该具有一些常规设置,如默认音量、默认播放模式、快捷键等。
用户可以根据自己的需求来调整这些设置。
以上是控制台C语言编写音乐播放器的主要功能。
根据以上功能,你可以开始设计和编写一个简单的音乐播放器应用程序。
当然,你可以根据个人需求和编程能力来扩展和优化这些功能。
最新一个简单的音乐播放器的java代码

import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.media.bean.playerbean.*;import java.io.IOException;import javax.swing.JOptionPane;import java.awt.*;public class lyt extends JFrame implements Runnable { public MediaPlayer soumd1;private JButton playSound, stopsound, tjian,loopSound; private JMenuItem jmiOpen,jmiSave,jmiExit,jmiAbout; public JPanel jp1, jp2, jp3, jp4;public JList jl;private JButton last, next, stop;public Vector vector, mingcheng;boolean fo = false, geshi = false;JLabel jl1, jl2, sj1, sj2;JTextField jt1, jt2;int a = 0, b = 0, you = 1, mm = 0;public lyt() {super("200842018java音乐播放器");soumd1 = new MediaPlayer();Container c = getContentPane();c.setLayout(new FlowLayout());mingcheng = new Vector();jp1 = new JPanel();c.add(jp1);JMenuBar mb=new JMenuBar();setJMenuBar(mb);JMenu fileMenu=new JMenu("文件");mb.add(fileMenu);JMenu helpMenu=new JMenu("帮助");mb.add(helpMenu);fileMenu.add(jmiOpen=new JMenuItem("打开"));fileMenu.add(jmiSave=new JMenuItem("播放")); helpMenu.add(jmiAbout=new JMenuItem("关于"));JPanel jp2 = new JPanel();jp2.setLayout(new FlowLayout());jp2.add(last = new JButton("后退"));jp2.add(playSound = new JButton("播放"));jp2.add(tjian = new JButton("添加"));jp2.add(next = new JButton("前进"));jp2.add(stopsound = new JButton("停止"));jp2.add(loopSound= new JButton("循环"));getContentPane().add(jp2, BorderLayout.SOUTH);jp2 = new JPanel();jp2.add(playSound);jp2.add(stopsound);c.add(jp2);jp4 = new JPanel();sj1 = new JLabel();sj2 = new JLabel();jp4.add(sj1);jp4.add(sj2);c.add(jp4);vector = new Vector();jl = new JList(mingcheng);jl.setVisibleRowCount(4);jl.setFixedCellHeight(30);jl.setFixedCellWidth(265);jl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION) ;c.add(new JScrollPane(jl));jp3 = new JPanel();jp3.add(tjian);c.add(jp3);try {String s = "d:\\music.txt";ObjectInputStream input = new ObjectInputStream( new FileInputStream(s));lujin a1 = (lujin) input.readObject();mingcheng = a1.b;vector = a1.a;jl.setListData(mingcheng);}catch (Exception e) {System.out.println("D盘没有保存音乐文件");}jmiOpen.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) {JFileChooser fileChooser = new JFileChooser();fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );fileChooser.setCurrentDirectory(new File("."));fileChooser.setFileFilter(newjavax.swing.filechooser.FileFilter() {public boolean accept(File file) {String name = file.getName().toLowerCase();return name.endsWith(".mp3")|| file.isDirectory();}public String getDescription() {return "音乐文件(*.mp3)";}});if (fileChooser.showOpenDialog(lyt.this) == JFileChooser.APPROVE_OPTION) {String fileName =fileChooser.getSelectedFile().getAbsolutePath();vector.add(fileName);StringBuffer buffer = daoxu(fileName);mingcheng.add(buffer);}}});tjian.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent event) {JFileChooser fileChooser = new JFileChooser();fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );fileChooser.setCurrentDirectory(newFile("."));fileChooser.setFileFilter(newjavax.swing.filechooser.FileFilter() {public boolean accept(File file) {String name =file.getName().toLowerCase();return name.endsWith(".mp3")|| file.isDirectory();}public String getDescription() {return "音乐文件(*.mp3)";}});if (fileChooser.showOpenDialog(lyt.this) == JFileChooser.APPROVE_OPTION) {String fileName =fileChooser.getSelectedFile().getAbsolutePath();vector.add(fileName);StringBuffer buffer = daoxu(fileName);mingcheng.add(buffer);}}});jmiSave.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());File ff = new File(yy);if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") || yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException eee) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});loopSound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String) vector.get(jl.getSelectedIndex());File ff = new File(yy);if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3")|| yy.matches("[\\S\\s]*.MP3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi=true;try {Thread.sleep(500);} catch (InterruptedException we) {}} elseJOptionPane.showMessageDialog(null,"不支持此格式,无法播放");} elseJOptionPane.showMessageDialog(null,"此歌曲文件已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});playSound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());File ff = new File(yy);if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") ||yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException eee) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}elseJOptionPane.showMessageDialog(null, "请选择音乐文件");}});stopsound.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {a = 0;b = 0;you = 0;mm = 0;geshi = false;fo = false;sj1.setText(null);sj2.setText(null);if (jl.getSelectedIndex() >= 0)soumd1.stop();}});jl.addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent event) {if (event.getClickCount() == 2) {if (jl.getSelectedIndex() >= 0) {String yy = (String)vector.get(jl.getSelectedIndex());File ff = new File(yy);if (ff.exists()) {if (yy.matches("[\\S\\s]*.mp3") ||yy.matches("[\\S\\s]*.mp3")) {if (soumd1 != null) {a = 0;b = 0;you = 0;soumd1.stop();}soumd1.setMediaLocation("file:/" + yy);fo = true;soumd1.start();geshi = true;try {Thread.sleep(500);}catch (InterruptedException e) {}}elseJOptionPane.showMessageDialog(null,"无法播放");}elseJOptionPane.showMessageDialog(null,"此歌曲已经存在");}}if (event.isMetaDown()) {if (jl.getSelectedIndex() >= 0) {int a = jl.getSelectedIndex();jt1.setText(mingcheng.get(jl.getSelectedIndex()) + "");jt2.setText(vector.get(jl.getSelectedIndex()) + "");}}}});addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {String s = "d:\\music.txt";mmm(vector, mingcheng, s);System.exit(0);}});setSize(370, 270);setVisible(true);}public void run() {while (true) {Date now = new Date();try {Thread.sleep(1000);}catch (InterruptedException e) {}if (geshi) {you = (int) soumd1.getMediaTime().getSeconds();mm = you % 60;if (you != 0)if (you % 60 == 0) {b++;}sj1.setText(b + ":" + mm);}}}public StringBuffer daoxu(String fileName) {String mc = "";for (int i = fileName.length(); i >= 1; i--) {if (fileName.charAt(i - 1) == '\\')break;mc += fileName.charAt(i - 1);}StringBuffer buffer = new StringBuffer(mc);StringBuffer mm = buffer.reverse();return mm;}public void mmm(Vector vector, Vector mingcheng, String lujin) {lujin a = new lujin(vector, mingcheng);try {ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(lujin));output.writeObject(a);output.flush();output.close();}catch (Exception e) {}}public static void main(String agrs[]) {lyt s = new lyt();Thread t1 = new Thread(s);t1.start();s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }class lujinimplements Serializable {Vector a = new Vector();Vector b = new Vector();public lujin(Vector vector, Vector mingcheng) {a = vector;b = mingcheng;}}}。
C#程序自作音乐视频播放器

一个简单的音乐视频系统建立一个项目:代码:点击窗体进入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.IO;namespace Windows音乐播放器{public partial class Form1 : Form{public Form1(){InitializeComponent();}string[] fileList = new string[10000]; // 定义播放列表数的最大值int numOfMusic; // 选中的媒体文件的索引号int selectOne; // 选中的音乐文件bool playOne = false; // 控制是否循环播放public void AddFile(string path){if (numOfMusic < 10000){numOfMusic += 1;fileList[numOfMusic] = path;}else{MessageBox.Show("不能添加文件!", "播放列表已满");}}public void AddFiles(string path, ListBox lstFiles){DirectoryInfo dir = new DirectoryInfo(path);foreach (FileInfo f in dir.GetFiles("*.mp3")){AddFile(f.FullName);int i;string strFile = Convert.ToString(numOfMusic);for (i = 1; i <= 5 - strFile.Length; i++){strFile += "";}strFile = ;lstFileList.Items.Add(strFile);}foreach (DirectoryInfo d in dir.GetDirectories()){AddFiles(d.FullName, lstFileList);}}public void DelFile(int selectNum){int i;for (i = selectNum; i <= numOfMusic - 1; i++){fileList[i] = fileList[i + 1];}numOfMusic -= 1;}public void CloseBtn(){btnPlay.Enabled = false;btnBack.Enabled = false;btnForward.Enabled = false;btnStop.Enabled = false;btnReplay.Enabled = false;btnDelete.Enabled = false;}private void Form1_Load(object sender, EventArgs e){lstFileList.Items.CopyTo(fileList, 0);// 将列表框(lstFileList)中的列表项全部复制到数组(fileList)中numOfMusic = 0; // 选中第一个媒体文件CloseBtn();}public void Play(int selectNum){mediaPlayer.URL = fileList[selectNum]; // 播放选中的媒体文件this.Text = "正在播放-- " + lstFileList.SelectedItem.ToString();}public void OpenBtn(){btnPlay.Enabled = true;btnBack.Enabled = true;btnForward.Enabled = true;}private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e){}private void butAddFile_Click(object sender, EventArgs e){int i;odlgMedia.FileName = ""; // 设置默认文件名odlgMedia.InitialDirectory = "C:\\"; // 设置默认路径odlgMedia.Filter = "mp3文件|*.mp3|所有文件|*.*"; // 设置文件类型if (odlgMedia.ShowDialog() == DialogResult.OK){string path = odlgMedia.FileName;FileInfo f = new FileInfo(path);AddFile(f.FullName);string strFile = Convert.ToString(numOfMusic);for (i = 1; i <= 5 - strFile.Length; i++){strFile += "";}strFile = ;lstFileList.Items.Add(strFile);if (lstFileList.Items.Count > 0){OpenBtn();}}}private void btnAddFiles_Click(object sender, EventArgs e){F.SelectedPath = "c:\\";fbdlaMedia.ShowNewFolderButton = true;fbdlaMedia.Description = "请选择媒体文件目录:";fbdlaMedia.ShowNewFolderButton = false;if (fbdlaMedia.ShowDialog() == DialogResult.OK){AddFiles(fbdlaMedia.SelectedPath, lstFileList);if (lstFileList.Items.Count > 0){OpenBtn();}}}private void btnDelete_Click(object sender, EventArgs e){int i = lstFileList.SelectedIndex;if (lstFileList.SelectedIndex >= 0){if ((selectOne == lstFileList.SelectedIndex + 1) && (mediaPlayer.URL != "")){MessageBox.Show("不能删除正在播放的文件", "错误");}else{DelFile(i + 1);lstFileList.Items.RemoveAt(i);if (i < lstFileList.Items.Count){lstFileList.SelectedIndex = i;}else if (lstFileList.Items.Count == 0){CloseBtn();}else{lstFileList.SelectedIndex = 0;}}}}private void btnPlay_Click(object sender, EventArgs e){if (lstFileList.SelectedIndex < 0){selectOne = 1;lstFileList.SelectedIndex = 0;}else{selectOne = lstFileList.SelectedIndex + 1;}Play(selectOne);tmrMedia.Enabled = true;btnStop.Enabled = true;btnReplay.Enabled = true;}private void lstFileList_SelectedIndexChanged(object sender, EventArgs e) {btnDelete.Enabled = true;}private void btnBack_Click(object sender, EventArgs e){if (lstFileList.SelectedIndex > 0){lstFileList.SelectedIndex -= 1;}else if (lstFileList.SelectedIndex == 0){lstFileList.SelectedIndex = lstFileList.Items.Count - 1;}else{lstFileList.SelectedIndex = numOfMusic - 1;}selectOne = lstFileList.SelectedIndex + 1;Play(selectOne);btnStop.Enabled = true;btnReplay.Enabled = true;}private void btnForward_Click(object sender, EventArgs e){if (lstFileList.SelectedIndex < lstFileList.Items.Count - 1){lstFileList.SelectedIndex = lstFileList.SelectedIndex + 1;}else{if (lstFileList.SelectedIndex > 0){lstFileList.SelectedIndex = 0;}}selectOne = lstFileList.SelectedIndex + 1;Play(selectOne);btnStop.Enabled = true;btnReplay.Enabled = true;}private void btnStop_Click(object sender, EventArgs e){mediaPlayer.URL = "";this.Text = "媒体播放器";tmrMedia.Enabled = false;btnReplay.Enabled = false;lstFileList.SelectedIndex = selectOne - 1;}private void btnReplay_Click(object sender, EventArgs e){if (playOne == true){playOne = false;btnReplay.FlatStyle = FlatStyle.Standard; // 设置按钮外观为三维btnReplay.Text = "单曲循环";}else{playOne = true;btnReplay.FlatStyle = FlatStyle.Popup; // 设置按钮外观为平面显示btnReplay.Text = "取消循环";}lstFileList.SelectedIndex = selectOne - 1;}private void lstFileList_DoubleClick(object sender, EventArgs e){// 双击播放列表中的媒体文件时,则播放该文件btnPlay_Click(sender, e);playOne = false;btnReplay.Text = "单曲循环";}private void tmrMedia_Tick(object sender, EventArgs e){// 用Timer控件控制连续播放if (mediaPlayer.playState == WMPLib.WMPPlayState.wmppsStopped){if (playOne == false){if (selectOne < lstFileList.Items.Count){selectOne += 1;}else if (selectOne == lstFileList.Items.Count){// 如果列表中所有媒体文件都播放完毕,则从头开始。
用C++编写音乐播放器

编写 CMyplayerDlg::Onplay()的代码, 播放选中的音乐, void CMyplayerDlg::Onplay() {
// TODO: Add your control notification handler code here this->m_multimedia.SetCommand("Play"); } 运行程序,便可对选中的音乐进行播放。 编写 CMyplayerDlg::Onpause()的代码, 暂停播放音乐 void CMyplayerDlg::Onpause() { // TODO: Add your control notification handler code here this->m_multimedia.SetCommand("Pause"); } 编写 CMyplayerDlg::Onclose()的代码, 关闭音乐 void CMyplayerDlg::Onclose() { // TODO: Add your control notification handler code here this->m_multimedia.SetCommand("Close"); this->m_pause.EnableWindow(FALSE); this->m_play.EnableWindow(FALSE); this->m_next.EnableWindow(FALSE); this->m_circle.EnableWindow(FALSE); this->m_close.EnableWindow(FALSE); } 编写 CMyplayerDlg::Onnext()的代码,实现选择下一首音乐 void CMyplayerDlg::Onnext() { // TODO: Add your control notification handler code here this->m_multimedia.SetCommand("Next"); Onopen(); this->m_multimedia.SetCommand("Play"); } 编写 CMyplayerDlg::Oncircle() 的代码,实现循环播放音乐 void CMyplayerDlg::Oncircle() { // TODO: Add your control notification handler code here int i; for(i=0;i<50;i++) { this->m_multimedia.SetCommand("Prev"); this->m_multimedia.SetCommand("Play");} } 最后,程序运行结果的界面如下:
微信小程序播放背景音乐的实例代码

微信⼩程序播放背景⾳乐的实例代码⽬录1.实现效果2.实现原理3.实现代码1.实现效果2.实现原理1、wx.getBackgroundAudioManager :获取全局唯⼀的背景⾳频管理器。
⼩程序切⼊后台,如果⾳频处于播放状态,可以继续播放。
但是后台状态不能通过调⽤API操纵⾳频的播放状态。
从微信客户端6.7.2版本开始,若需要在⼩程序切后台后继续播放⾳频,需要在 app.json 中配置 requiredBackgroundModes 属性。
开发版和体验版上可以直接⽣效,正式版还需通过审核。
2、onUnload和onHide事件中暂停⾳乐的播放。
3、onShow中调⽤播放事件4、在播放结束的事件中,再次播放,以达到循环播放的效果。
3.实现代码<image src="{{checked?'../img/stop.png':'../img/play.png'}}" class="music {{!checked && 'circle'}}" catchtap="checkMusic"></image> <view catchtap="toNext" class="btn"> 去下⼀个页⾯</view>page {background-color: aliceblue;}.music {width: 86rpx;height: 86rpx;position: absolute;top: 108rpx;right: 10rpx;z-index: 99;}.circle {animation: cirlce 4s linear infinite;}@keyframes cirlce {0% {transform: rotate(0deg);}100% {transform: rotate(359deg);}}.btn {margin: 550rpx auto 0;width: 625rpx;height: 80rpx;background: linear-gradient(90deg, #dd8449 0%, #e28e74 52%, #dbb290 100%);border-radius: 6rpx;font-size: 30rpx;color: #fff;line-height: 80rpx;text-align: center;position: relative;overflow: hidden;}.btn:after {content: "";background: #999;position: absolute;width: 750rpx;height: 750rpx;left: calc(50% - 375rpx);top: calc(50% - 375rpx);opacity: 0;margin: auto;border-radius: 50%;transform: scale(1);transition: all 0.4s ease-in-out;}// pages/effects/audioCust/index.jsPage({data: {checked: false,},onShow: function () {this.player(wx.getBackgroundAudioManager())},checkMusic() {console.log(11)this.setData({checked: !this.data.checked})if (this.data.checked) {wx.getBackgroundAudioManager().pause();} else {this.player(wx.getBackgroundAudioManager())}},player(e) {e.title = '苏苏的⾳乐'e.src = "/song/media/outer/url?id=36587407.mp3"//⾳乐播放结束后继续播放此⾳乐,循环不停的播放e.onEnded(() => {this.player(wx.getBackgroundAudioManager())})},// 页⾯卸载时候暂停播放(不加页⾯将⼀直播放)onUnload: function () {wx.getBackgroundAudioManager().stop();},// ⼩程序隐藏时候暂停播放(不加页⾯将⼀直播放)onHide() {wx.getBackgroundAudioManager().stop();},toNext() {wx.navigateTo({url: '/pages/jsCase/draw/index',})}})到此这篇关于微信⼩程序播放背景⾳乐的⽂章就介绍到这了,更多相关⼩程序播放背景⾳乐内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!。
C#开发音乐播放器

功能简介:1、循环模式:顺不播放axWMusicPlayer.settings.setMode("shuffle", false);全部循环axWMusicPlayer.settings.setMode("loop", true);随机播放axWMusicPlayer.settings.setMode("shuffle", true);2、模拟定时关机程序写到定时关机,具体的调用定时关机程序省略了,程序中相应地方有注解。
定时关机代码1 private void 关机时间toolStripTextBox_KeyPress(object sender, KeyPressEventArgs e)2 {3 if (e.KeyChar == (char)Keys.Enter && 关机时间toolStripTextBox.Text != "")4 {5 try6 {7 DateTime time = DateTime.Parse(关机时间toolStripTextBox.Text);8 Timefont font = new Timefont(time.Hour, time.Minute, 0);9 if (pareTo(new Timefont(DateTime.Now.Hour, DateTime.Now.Minute, 0)) == 0) //当前关机时间10 {11 if (MessageBox.Show("你设定的关机时间是当前计算机时间,是否直接关机?", "提示", MessageBoxButtons.YesNo, rmation) == DialogResult.OK)12 {13 MynotifyIcon.Icon = Icon.ExtractAssociatedIcon(PathBase + "\\Images\\" +"ShutDown_notifyIcon.ico");14 //15 //调用关机程序16 //17 }18 else19 {20 return;21 }22 }23 if (pareTo(new Timefont(DateTime.Now.Hour, DateTime.Now.Minute, 0)) < 0) //过去关机时间24 {25 MessageBox.Show("此时间已是过去时间,设定无效", "提示", MessageBoxButtons.OK, rmation);26 return;27 }28 if (pareTo(new Timefont(DateTime.Now.Hour, DateTime.Now.Minute, 0)) > 0) //有效关机时间29 {3031 ShutDownTime = 关机时间toolStripTextBox.Text;32 MessageBox.Show("成功设置定时关机,计算机将于“" + ShutDownTime + "”关机…… *︶︵︶*", "提示", MessageBoxButtons.OK, rmation);33 this.关机时间toolStripTextBox.Visible = false;34 this.取消定时关机QToolStripMenuItem.Visible = true;3536 //37 //调用关机程序38 //39 }40 }41 catch42 {43 MessageBox.Show("日期格式不正确,请重新输入。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
基础知识: 乐音的音调是由频率决定 音符是构成一首曲子的基本元素 我们的目的是产生——一组固定 的频率来表示音符
频率和音符的ቤተ መጻሕፍቲ ባይዱ应关系
2 3 4 5 6 音符 1 频率 131 147 165 175 196 220 2 3 4 5 6 音符 1 频率 294 330 349 392 440 492 7 262 7 523
2 3 4 5 6 7 音符 1 频率 587 659 697 783 879 983 1046
节拍的产生
就是延时 一般是每秒 96拍 在一个节拍里让单片机保持输出一个固定 频率
硬件电路
软件规划
4首曲子循环播放 定时器1产生频率 定时器2产生节拍 主程序完成曲目的调用
主程序设计
main() { InitDevice(); PlaySong(Pass); while(1) { PlaySong(JingleBells); PlaySong(Pass); PlaySong(SOS); PlaySong(Pass); PlaySong(Yesterday); PlaySong(Pass); PlaySong(BeatIt); PlaySong(Pass); } }
�