1

組み込み Linux 用の Qt アプリで mp3 ファイルの再生のサポートを追加したいと考えています。

Qt でフォノンを使用できません。.pro ファイルに QT += フォノンを追加すると、コンパイル中に次のエラーが表示されます: /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/ libphonon.so: `QWidget::x11Event(_XEvent*)' への未定義の参照

/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/libphonon.so: `QDataStream::QDataStream(QByteArray*, int)' への未定義の参照

collect2: ld が 1 つの終了ステータスを返しました

だから今、mp3ファイルのデコードにmpg123 libを使用することを考えています。

ライブラリを Qt に統合するのに助けが必要です。Qt で純粋な C++ ライブラリを使用したことがないため、統合する方法についてはあまり考えていません。

4

2 に答える 2

1

みなさん、こんにちは!! やっとわかった!!

int MP3Player::Init(const char *pFileName)

{

    mpg123_init();

    m_mpgHandle = mpg123_new(0, 0);
    if(mpg123_open(m_mpgHandle, pFileName) != MPG123_OK)
    {
        qFatal("Cannot open %s: %s", pFileName, mpg123_strerror(m_mpgHandle));
        return 0;
    }
}

int MP3Player::Play()

{

    unsigned char *audio;
    int mc;
    size_t bytes;
    qWarning("play_frame");


    static unsigned char* arr = 0;

    /* The first call will not decode anything but return MPG123_NEW_FORMAT! */

    mc = mpg123_decode_frame(m_mpgHandle, &m_framenum, &audio, &bytes);

    if(bytes)
    {

        /* Normal flushing of data, includes buffer decoding. */

        /*This function is my already implemented audio class which uses ALSA to output decoded audio to Sound Card*/
        if (m_audioPlayer.Play(arr,bytes) < (int)bytes) 
        {
            qFatal("Deep trouble! Cannot flush to my output anymore!");
        }

    }
    /* Special actions and errors. */
    if(mc != MPG123_OK)
    {
        if(mc == MPG123_ERR)
        {
            qFatal("...in decoding next frame: %s", mpg123_strerror(m_mpgHandle));
            return CSoundDecoder::EOFStream;

        }
        if(mc == MPG123_DONE)
        {
            return CSoundDecoder::EOFStream;
        }
        if(mc == MPG123_NO_SPACE)
        {
            qFatal("I have not enough output space? I didn't plan for this.");
            return CSoundDecoder::EOFStream;
        }
        if(mc == MPG123_NEW_FORMAT)
        {
            long iFrameRate;
            int encoding;
            mpg123_getformat(m_mpgHandle, &iFrameRate, &m_iChannels, &encoding);

            m_iBytesPerChannel = mpg123_encsize(encoding);

            if (m_iBytesPerChannel == 0)
                qFatal("bytes per channel is 0 !!");

            m_audioPlayer.Init(m_iChannels , iFrameRate , m_iBytesPerChannel);

        }
    }
}
于 2010-12-28T06:10:05.663 に答える
0

mpg123 を QT プロジェクトで動作させるには、次の手順を試してください。

1. mpg123 をダウンロードしてインストールします: 解凍したフォルダー (例: /home/mpg123-1.13.0/) から ./configure を実行し、「sudo make install」を実行します。

2. エラーがない場合は、この行を *.pro ファイルに追加します

LIBS += /usr/local/lib/libmpg123.so

3.次に、以下のコードは正常に実行されるはずです。

#include "mpg123.h"
#include <QDebug>

void MainWindow::on_pushButton_2_clicked()
{
    const char **decoders = mpg123_decoders();
    while (*decoders != NULL)
    {
        qDebug() << *decoders;
        decoders++;
    }
}

または、システムコール経由で mpg123 を呼び出すこともできます:

system("mpg123 /home/test.mp3"); 

これが役に立てば幸いです、よろしく

于 2010-12-24T20:31:39.587 に答える