c++怎样播放mp3 - 爱问答

(爱问答)

c++怎样播放mp3

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 ",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 ");

return;

}

}


下一篇:我这个电脑配置可以玩apex英雄吗

上一篇:win10系统盘中MATS是什么文件夹

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?