在我的项目中使用Phonon是不可取的。因此决定使用QAudioOutput和解码器Lame。通过QNetworkReply从网络获得的数据并尝试解码4096字节的块,但是我得到了一个错误。我理解我的行为不正确,因为我无法找到解释如何去做。我想我需要跳过ID3标签并使用干净的数据
#include <QtNetwork>
#include <QObject>
#include <lame/lame.h>
class Decoder:public QObject
{
Q_OBJECT
public:
QNetworkReply* _reply;
explicit Decoder(QNetworkReply *reply,QObject *parent=0):
QObject(parent),
_reply(reply)
{
QObject::connect(reply,SIGNAL(downloadProgress(qint64,qint64)),SLOT(readData(qint64,qint64));
}
public slots:
void readData(qint64 ready,qint64 total )
{
if ((_reply->size() > 4096) || (ready == total))
{
QByteArray data = _reply->read(4096);
qint16 l_buf[4096*100];
qint16 r_buf[4096*100];
hip_t decoder = hip_decode_init();
qint32 decoded = hip_decode(decoder,(unsigned char*)data.data(),data.size(),l_buf,r_buf);
}
}