Visual c++ 使用mpg123 visual c+时没有声音+; 我试图用MPG123在VisualC++项目中播放一首歌,我用的是一个代码,但我找不到如何发出声音。代码没有错误,工作正常但立即关闭,这是代码,谢谢: #include "stdafx.h

Visual c++ 使用mpg123 visual c+时没有声音+; 我试图用MPG123在VisualC++项目中播放一首歌,我用的是一个代码,但我找不到如何发出声音。代码没有错误,工作正常但立即关闭,这是代码,谢谢: #include "stdafx.h,visual-c++,Visual C++,使用mpg123 visual c+时没有声音+; 我试图用MPG123在VisualC++项目中播放一首歌,我用的是一个代码,但我找不到如何发出声音。代码没有错误,工作正常但立即关闭,这是代码,谢谢: #include "stdafx.h" #include <mpg123.h> #define INBUFF 16384 #define OUTBUFF 32768 int _tmain(int argc, _TCHAR* argv[]) { mpg1

使用mpg123 visual c+时没有声音+; 我试图用MPG123在VisualC++项目中播放一首歌,我用的是一个代码,但我找不到如何发出声音。代码没有错误,工作正常但立即关闭,这是代码,谢谢:

#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;
}
#包括“stdafx.h”
#包括
#定义INBUFF 16384
#定义溢出32768
int _tmain(int argc,_TCHAR*argv[]
{
mpg123_手柄*mh;
常量字符*文件名;
filename=“D:/Jose.mp3”;
无符号字符*缓冲区;
大小\u t缓冲区\u大小;
尺寸未完成;
INTERR;
int通道,编码;
长期利率;
mpg123_init();
mh=mpg123_新(空值和错误);
缓冲区大小=mpg123输出块(mh);
buffer=(无符号字符*)malloc(buffer_size*sizeof(无符号字符));
/*打开文件并获取解码格式*/
mpg123_打开(mh,文件名);
mpg123_getformat(mh、速率、通道和编码);
/*设置输出格式并打开输出设备*/
int m_bits=mpg123_encsize(编码);
int m_比率=比率;
int m_通道=通道;
/*解码播放*/
对于(int TOTALLBTYES=0;mpg123_读取(mh、缓冲区、缓冲区大小和完成)==mpg123_正常;){
totalBtyes+=完成;
}
/*清理*/
自由(缓冲);
mpg123_关闭(mh);
mpg123_删除(mh);
mpg123_退出();
返回0;
}

<代码> >如果你在编码C++,为什么你使用的是代码> MalC/C > <代码>免费< /代码>而不是<代码>新的< /代码> />代码>删除<代码>?程序只读取你提供的文件,它不尝试播放任何东西。对不起,我是新的使用MPG123,我认为解码和播放的部分是用来播放歌曲的,你知道如何使用mpg123播放歌曲吗?