Frage

Ich will die Unterstützung für die Wiedergabe von MP3-Datei in meiner Qt App für Embedded Linux.

Ich bin nicht in der Lage Phonon in Qt zu verwenden. Nach der Zugabe von QT + = Phonon in .proDatei gibt es mir die folgenden Fehler beim Kompilieren: /usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/libphonon.so: undefined reference to `QWidget :: x11Event (_XEvent *)

/usr/lib/gcc/i486-linux-gnu/4.4.1 /../../../../ lib / libphonon.so: undefined reference to `QDataStream :: QDataStream (QByteArray *, int)

collect2: ld returned 1 exit status

So, jetzt von Ich denke, das mpg123 lib mit MP3-Dateien für die Decodierung.

Ich brauche Hilfe, um die Bibliothek in Qt zu integrieren. Ich habe noch nie eine reine c ++ Bibliothek in Qt verwendet vor, so dass ich viel Ahnung haben, nicht, wie es zu integrieren.

War es hilfreich?

Lösung

Hey alle !! Schließlich habe ich es aus !!

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);

        }
    }
}

Andere Tipps

Um mpg123 Arbeiten mit Ihrem QT Projekt zu erhalten versuchen Sie folgende Schritte:

1.download und installieren mpg123: aus dem Ordner, in dem es extrahiert (z /home/mpg123-1.13.0/) run configure und dann "sudo make install"

2.if gibt es keine Fehler setzen Sie diese Zeile in Ihre * .proDatei

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

3.then Code unten sollte in Ordnung für Sie ausführen:

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

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

Alternativ können Sie mpg123 über Systemaufruf aufrufen:

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

hoffe, das hilft, Grüße

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top