c语言音乐视频,C语言播放音乐(DOS)

#include

#include

#include

#include

#pragma comment(lib,"winmm.lib")

#include

using namespace std;

char buf[50];

MCIERROR mcierror;

string song_name,mci_string;

char time_all[60];

int dwlong;

bool first_song=true;

void play();

void main()

{

song_name="cg.mp3";

first_song=false;

play();

while (1)

{

mciSendString("status 设备1 position",buf,sizeof(buf),NULL);//获取播放歌曲的进度,

int position=atoi(buf);//转化为整型数据

printf("当前进度:%d\r",position);

if(position>=dwlong)

{

mciSendString("close 设备1",buf,sizeof(buf),NULL); //这一布至关重要,要先把已经播放完的设备先关闭,因为不能够出现同名的设备名"设备1"!!

if (first_song==false)

{

song_name="cg.mp3";

first_song=true;

}

else

{

song_name="cg.mp3";

first_song=false;

}

position=0;

system("cls");

play();

}

Sleep(1000);//Sleep()的功能是让主调进程休息一个时间段执行睡眠,时间段过后继续调度,参数是毫秒级,1000毫秒=1秒,在这里是每隔一秒刷新一次显示频...    }

}

void play()

{

mci_string="open "+song_name+" alias 设备1";

mcierror=mciSendString(mci_string.c_str(),buf,50,NULL);//命令"open 1.mp3  alias 设备1"也可以写成"open 1.mp3 type mpegvideo alias 设备1",不写的话系统会自己寻找对应设备。"alias 设备1"是另外起名为设备1,以后播放的时候直接用"设备1"即可。

if (mcierror)

{

mciGetErrorString(mcierror,buf,strlen(buf));

printf("%s",buf);

return;

}

mciSendString("set 设备1 time format TMSF",buf,50,NULL);//设置时间格式为分秒格

mciSendString("status 设备1 length ",buf,sizeof(buf),NULL); //获取歌曲长度信息

dwlong=atoi(buf);//把时间转化为整数。

printf("歌曲名称:%s\n歌曲长度:%d\n",song_name.c_str(),dwlong);

mciSendString("play 设备1 repeat",buf,50,NULL);//如果要单首歌曲循环播放。"play 设备1 repeat"

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值