我正在尝试在视觉c ++项目中使用mpg123播放一首歌,我正在使用此处的代码,但我找不到如何制作声音。代码没有错误,它可以正常但立即关闭,这是代码,谢谢:
#include "stdafx.h"
#include <mpg123.h>
#define INBUFF 16384
#define OUTBUFF 32768
int _tmain(int argc, _TCHAR* argv[])
{
mpg123_handle *mh;
const char* filename;
filename="D:/Jose.mp3";
unsigned char *buffer;
size_t buffer_size;
size_t done;
int err;
int channels, encoding;
long rate;
mpg123_init();
mh = mpg123_new(NULL, &err);
buffer_size = mpg123_outblock(mh);
buffer = (unsigned char*) malloc(buffer_size * sizeof(unsigned char));
/* open the file and get the decoding format */
mpg123_open(mh, filename);
mpg123_getformat(mh, &rate, &channels, &encoding);
/* set the output format and open the output device */
int m_bits = mpg123_encsize(encoding);
int m_rate = rate;
int m_channels = channels;
/* decode and play */
for (int totalBtyes = 0 ; mpg123_read(mh, buffer, buffer_size, &done) == MPG123_OK;) {
totalBtyes += done;
}
/* clean up */
free(buffer);
mpg123_close(mh);
mpg123_delete(mh);
mpg123_exit();
return 0;
}