利用VS2013中的C++编辑器进行操作,没有成功播放音乐,想问下原因是什么?

给你的爱在西元前 2019-05-29 04:51:08
#include<iostream>
#include<windows.h>
#pragma comment (lib,"winmm.lib")

using namespace std;
class automobile
{
private:
char type[20];
char color[20];
float price;
int carry_weight;
int carry_customer;
public:
void set_data(char *t, char *c, float pri, int cw, int cc);
void movecar(int l, int k);
void downcar(int l);
void horming(int num);
void play_MP3(char *ps);
char *show_type(){ return type; };
};
void automobile::set_data(char *t, char *c, float pri, int cw, int cc)
{
strcpy_s(type, t);
strcpy_s(color, c);
price = pri;
carry_weight = cw;
carry_customer = cc;
}
void automobile::movecar(int l, int k)
{
cout << "\n" << type << "水平直线运动" << endl;
for (int i = 0; i < l;i++)
{
cout << ' ' << "o_o";
Sleep(1000 / k);
cout << "\b\b\b";
}
}
void automobile::downcar(int l)
{
cout << "\n" << type << "垂直下降运动:" << endl;
for (int i = 0; i < l;i++)
{
cout << "o_o";
Sleep(500);
cout << "\b\b\b" << " ";
cout << endl;
}
}
void automobile::horming(int num)
{
for (int i = 0; i < num;i++)
{
cout << type;
cout << '\007' << " di..." << endl;
Sleep(1000);
}
}
void automobile::play_MP3(char *ps)
{
char str[100] = "play ";
strcat_s(str, ps);
cout << str;
mciSendStringA(str, NULL, 0, NULL);
char a;
cin >> a; //输入任何字符结束播放
}

int main()
{
automobile nison;
char tp[] = "yyida";
char ys[] = "white";
nison.set_data(tp, ys, 200000, 5, 3);
nison.horming(3);
nison.movecar(5, 3);
nison.downcar(3);
char mp[] = "C:\\songtian.mp3";
nison.play_MP3(mp);
return 0;
}
第一次求助,谢谢啦
...全文
246 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_43974873 2019-07-02
  • 打赏
  • 举报
回复
我用的vs2019
  • 打赏
  • 举报
回复
引用 4 楼 赵4老师 的回复:
先参考一下MSDN98中自带的MCI相关例子吧:MSDN98\SAMPLES\VC98\SDK\GRAPHICS\AUDIO\MCIAPP\MCIAPP.C
MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl
好的,谢谢!
  • 打赏
  • 举报
回复
引用 3 楼 zjq9931 的回复:
用playsound函数播放试试。
好的!
  • 打赏
  • 举报
回复
用格式工厂将.mp3转成了.wav格式,调试后还是没有成功播放
赵4老师 2019-05-30
  • 打赏
  • 举报
回复
先参考一下MSDN98中自带的MCI相关例子吧:MSDN98\SAMPLES\VC98\SDK\GRAPHICS\AUDIO\MCIAPP\MCIAPP.C MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl
  • 打赏
  • 举报
回复
用playsound函数播放试试。
  • 打赏
  • 举报
回复
只能播放.wav文件。 不支持mp3文件

64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧