怎么在VS编的程序中,C++语言,播放音频文件
3个回答
展开全部
用playsound函数。选项见:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
例如:
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
void main()
{
PlaySound(TEXT("recycle.wav"), NULL, SND_FILENAME);
while (1)
{
printf("program is running... here\n");
Sleep(1000);
}
exit(0);
}
http://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx
例如:
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
void main()
{
PlaySound(TEXT("recycle.wav"), NULL, SND_FILENAME);
while (1)
{
printf("program is running... here\n");
Sleep(1000);
}
exit(0);
}
追问
那些头文件都需要放在项目的哪些目录?
追答
应该是放在编译程序的的文件夹里。头文件一般都在一个文件夹里。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-03-02
展开全部
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[5];
int i,j,k;
for(i=0;i<=4;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
if(a[i]>a[j])
{
k=a[i]; a[i]=a[j]; a[j]=k;
}
}
}
printf("еепР╫А╧Шйгё╨\n");
for(i=0;i<=4;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-03-17 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
C++语言中播放音频文件的方法如下:
1:Playsound函数
事例代码如下
#include<windows.h>
#include<stdio.h>
#pragma comment(lib,"WinMM.Lib")
void main()
{
PlaySound("c:\\dui12.wav",NULL,SND_FILENAME|SND_ASYNC);
}
2:和Playsound函数类似的undplaysound函数
#include<windows.h>
#include<stdio.h>
#pragma comment(lib,"WinMM.Lib")
void main()
{
undPlaySound("c:\\dui12.wav",NULL,SND_FILENAME|SND_ASYNC);
}
3:功能强大的函数,支持混音的MCI类
事例代码如下
#include<windows.h>
#include "mmsystem.h"//导入声音头文件
#pragma comment(lib,"winmm.lib")//导入声音头文件库
#include<stdio.h>
void PlayMp3() ;
void main()
{
PlayMp3() ;
PlaySound("C:\\Normal2.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
system("pause");
}
void PlayMp3()
{
char buf[128];
char str[128] = {0 };
int i = 0;
//use mciSendCommand
MCI_OPEN_PARMS mciOpen;
MCIERROR mciError;
//SetWindowText(NULL,"12345");
mciOpen.lpstrDeviceType = "mpegvideo";
mciOpen.lpstrElementName = "c:\\WELCOME.WAV";
mciError = mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,(DWORD)&mciOpen);
if(mciError)
{
mciGetErrorString(mciError,buf,128);
printf("send MCI_OPEN command failed:%s\n",buf);
return;
}
UINT DeviceID = mciOpen.wDeviceID ;
MCI_PLAY_PARMS mciPlay;
mciError = mciSendCommand(DeviceID,MCI_PLAY,0 ,(DWORD)&mciPlay);
if(mciError)
{
printf("send MCI_PLAY command failed\n");
return;
}
}
1:Playsound函数
事例代码如下
#include<windows.h>
#include<stdio.h>
#pragma comment(lib,"WinMM.Lib")
void main()
{
PlaySound("c:\\dui12.wav",NULL,SND_FILENAME|SND_ASYNC);
}
2:和Playsound函数类似的undplaysound函数
#include<windows.h>
#include<stdio.h>
#pragma comment(lib,"WinMM.Lib")
void main()
{
undPlaySound("c:\\dui12.wav",NULL,SND_FILENAME|SND_ASYNC);
}
3:功能强大的函数,支持混音的MCI类
事例代码如下
#include<windows.h>
#include "mmsystem.h"//导入声音头文件
#pragma comment(lib,"winmm.lib")//导入声音头文件库
#include<stdio.h>
void PlayMp3() ;
void main()
{
PlayMp3() ;
PlaySound("C:\\Normal2.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
system("pause");
}
void PlayMp3()
{
char buf[128];
char str[128] = {0 };
int i = 0;
//use mciSendCommand
MCI_OPEN_PARMS mciOpen;
MCIERROR mciError;
//SetWindowText(NULL,"12345");
mciOpen.lpstrDeviceType = "mpegvideo";
mciOpen.lpstrElementName = "c:\\WELCOME.WAV";
mciError = mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,(DWORD)&mciOpen);
if(mciError)
{
mciGetErrorString(mciError,buf,128);
printf("send MCI_OPEN command failed:%s\n",buf);
return;
}
UINT DeviceID = mciOpen.wDeviceID ;
MCI_PLAY_PARMS mciPlay;
mciError = mciSendCommand(DeviceID,MCI_PLAY,0 ,(DWORD)&mciPlay);
if(mciError)
{
printf("send MCI_PLAY command failed\n");
return;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询