Question

Je veux ajouter support pour la lecture de fichier mp3 dans mon application Qt pour Linux embarqué.

Je ne suis pas en mesure d'utiliser phonon dans Qt. Après avoir ajouté QT + = phonon dans .pro fichier, il me donne l'erreur suivante lors de la compilation: /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 a renvoyé 1 état de sortie

Alors maintenant, je pense à l'aide de la mpg123 lib pour décoder les fichiers mp3.

Je besoin d'aide dans l'intégration de la bibliothèque Qt. Je ne l'ai jamais utilisé un pur c ++ bibliothèque Qt avant donc je n'ai pas beaucoup idée sur la façon de l'intégrer.

Était-ce utile?

La solution

Salut à tous !! Enfin j'ai tout compris !!

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

        }
    }
}

Autres conseils

Afin d'obtenir mpg123 travail avec votre projet QT vous essayez les étapes suivantes:

1.download et installer mpg123: à partir du dossier où vous avez extrait à (/home/mpg123-1.13.0/ par exemple) puis exécuter ./configure "make sudo install"

2.if il n'y a aucune erreur de mettre cette ligne à votre fichier * .pro

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

Code 3.Then ci-dessous devrait fonctionner pour vous:

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

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

Vous pouvez aussi faire mpg123 par appel système:

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

espérons que cette aide, ce qui a trait

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top