当前位置:文档之家› 多媒体音乐播放器实验报告

多媒体音乐播放器实验报告

}
曲目菜单函数 void playlist(string *str,int i) {
cout<<"----------------曲目列表---------------"<<endl; for(int j=0;j<i;j++) {
cout<<"编号: "<<j+1<<" "<<str[j]<<endl; } cout<<"---------------请选择编号--------------"<<endl; }
实验内容:使用VC6.0编写音乐播放

实验原理:主要使用PlaySound这个函数,此函数可以用于播放wav格式 的音乐文件。 以下是播放函数。其中path是音乐文件的所在地址。 void paly(string path) {
LPCSTR str=path.c_str(); PlaySound(str,NULL, SND_ASYNC|SND_NODEFAULT ); } 以下是停止播放的函数。 void pause() { PlaySound(NULL,NULL,NULL); } 在这里为了便于实验的方便,我所使用的路径都是在这个项目的文件 夹里,即把音乐文件和cpp文件放在一起,这样子方便实验。 下面是生成一个曲目列表头文件list.h。通过这个函数可以在list.txt中 生成曲目列表。 #include<iostream> #include<windows.h> #include<vector> #include<fstream> #include<string> using namespace std; char * filename[20] = {0}; void list() { system("dir /B/A-D > filelist.txt"); ifstream input; ofstream out; out.open("list.txt"); input.open("filelist.txt"); if(!input.is_open())
cerr << "Couldn't open the file haiku.txt/number.txt" << endl;
string value; while (getline(input,value)) {
int a = value.find(".wav"); if(a!=-1) out<<valueБайду номын сангаас<endl; }
通过选择编号来播放音乐,如果需要添加音乐,只需在文件夹中加就 行了。
以上就是主要的函数和头文件。具体代码见原文件。 以下是运行图:
我把exe文件放在了外面,这样无需编译,或者移动音乐文件就可播放 了。
相关主题