Unable to play a wav file with Audio component


  • Lifetime Qt Champion

    Because it's using ALSA directly.

    Did you try to build the ALSA backend for Qt Multimedia ?



  • Yes, I think so.

    I can find libqtaudio_alsa.so in /usr/lib/qt/plugins.


  • Lifetime Qt Champion

    Start your application with QT_DEBUG_PLUGINS=1 to see if there's a problem when loading the plugin.



  • At first glance, the plugins get loaded.

    Got keys from plugin meta data ("alsa")
    QFactoryLoader::QFactoryLoader() looking at "/usr/lib/qt5/plugins/audio/libqtaudio_alsa.so.new"
    Found metadata in lib /usr/lib/qt5/plugins/audio/libqtaudio_alsa.so.new, metadata=
    {
        "IID": "org.qt-project.qt.audiosystemfactory/5.0",
        "MetaData": {
            "Keys": [
                "alsa"
            ]
        },
        "className": "QAlsaPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("alsa")
    QFactoryLoader::QFactoryLoader() checking directory path "/opt/pga/audio" ...
    loaded library "/usr/lib/qt5/plugins/audio/libqtaudio_alsa.so"
    

    :(


  • Lifetime Qt Champion

    Looks good on that point.

    Did you check which output QtMultimedia sees as available ?



  • What do you mean exactly ?

    Yesterday, in the main.cpp, I dumped the

    QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)
    

    Is that what you meant ? And yes, it dumps the same devices as with

    aplay -L
    

  • Lifetime Qt Champion

    That's that yes and the result also looks good.

    Did you check whether the element raises an error ?



  • No error raised.

    However, in the onClick() handler where idPlay->play() is launched (see code snippet above..),
    I traced the values of some properties of tha Audio component.

    qml: status =  2
    qml: playvolume =  1
    qml: muted =  false
    qml: error code =  0 , string=
    qml: src =  file:///opt/pga/track00.wav
    qml: availability =  0
    qml: duration =  -1
    qml: hasAudio =  false
    

    Weird. duration = -1, hasAudio = false and however, no error code / string...


  • Lifetime Qt Champion

    The path to the file looks different from your QML sample code.



  • Yes, because I changed the path between my tests, but the paths are valids.

    I really don't understand why Qt does not raise any error.
    Everything looks correct.
    status = 2, that is: "the Media has been loaded".

    So it looks like a final phase is not complete. Isn't it ?


  • Lifetime Qt Champion

    Can you test the functionality with C++ ?



  • I've put this sample code in the C++ side:

    init()
    {
    ...
     connect(&m_player, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(on_mediaPlayer_error(QMediaPlayer::Error)));^
     connect(&m_player, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(on_mediaPlayer_stateChanged(QMediaPlayer::State)));^
     connect(&m_player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, 
    SLOT(on_mediaPlayer_mediaStatusChanged(QMediaPlayer::MediaStatus)));
    
    qDebug() << "Attempt to read mediacontent";
    QMediaContent content(QUrl::fromLocalFile("/opt/pga/track00.wav"));
    qDebug() << "MediaContent: isNull = " << content.isNull();
    m_player.setMedia(content);
    m_player.play();
    }
    

    Each of the slots above print the value of their respective parameter in stdout.

    Output from my host linux:

    Attempt to read mediacontent
    MediaContent: isNull =  false
    <MainWindow::on_mediaPlayer_mediaStatusChanged> status =  QMediaPlayer::LoadingMedia
    <MainWindow::on_mediaPlayer_stateChanged> state =  QMediaPlayer::PlayingState
    <MainWindow::on_mediaPlayer_mediaStatusChanged> status =  QMediaPlayer::BufferedMedia
    

    Output from my colibri-t20:

    Attempt to read mediacontent
    MediaContent: isNull =  false
    <MainWindow::on_mediaPlayer_mediaStatusChanged> status =  QMediaPlayer::LoadingMedia
    

    It's stuck on LoadingMedia.
    No more.

    :(


  • Lifetime Qt Champion

    Ok...

    You should rebuilt the plugin uncommenting the DEBUG_AUDIO define to see if it gives you more information about what is happening.



  • Hi,

    Unfortunately it doesn't trace more information at all...

    Found metadata in lib /usr/lib/qt5/plugins/audio/libqtaudio_alsa.so, metadata=
    {
        "IID": "org.qt-project.qt.audiosystemfactory/5.0",
        "MetaData": {
            "Keys": [
                "alsa"
            ]
        },
        "className": "QAlsaPlugin",
        "debug": false,
        "version": 328961
    }
    
    
    Got keys from plugin meta data ("alsa")
    QFactoryLoader::QFactoryLoader() checking directory path "/opt/pga/audio" ...
    loaded library "/usr/lib/qt5/plugins/audio/libqtaudio_alsa.so"
    DeviceInfo name =  "sysdefault:CARD=colibrit20wm971" , codecs =  "audio/pcm"
    DeviceInfo name =  "default:CARD=colibrit20wm971" , codecs =  "audio/pcm"
    DeviceInfo name =  "default" , codecs =  "audio/pcm"
    Default OutputDevice:  "sysdefault:CARD=colibrit20wm971"
    Attempt to read mediacontent
    MediaContent: isNull =  false
    <MainWindow::on_mediaPlayer_mediaStatusChanged> status =  QMediaPlayer::LoadingMedia , bufferStatus =  0
    <MainWindow::initialize()> : bufferStatus =  0
    screen dpi =  96.1517
    screen geo =  QRect(0,0 480x800)
    QFactoryLoader::QFactoryLoader() checking directory path "/usr/lib/qt5/plugins/accessiblebridge" ...
    QFactoryLoader::QFactoryLoader() checking directory path "/opt/pga/accessiblebridge" ...
    QSGContext::initialize: stencil buffer support missing, expect rendering errors
    Updating catalog.
    <MediaCatalog::roleNames() > called.
    qml: size of catalog:  3
    qml: playlaunched...status =  1
    qml: playvolume =  1
    qml: muted =  false
    qml: error code =  0 , string=
    qml: src =
    qml: availability =  0
    qml: duration =  -1
    qml: hasAudio =  false
    

  • Lifetime Qt Champion

    Does the device info look correct for your system ?
    Can you compare with that aplay uses ?



  • Yes, it is always the same.

    I have also edited the qalsaaudiooutput.cpp and added some fprintf() statements and nothing is displayed in the console.
    I put a message in open() and in the constructor

    However, it prints loaded library "/usr/lib/qt5/plugins/audio/libqtaudio_alsa.so"

    I don't know what I can do to figure out what's happening.


  • Lifetime Qt Champion

    Did you install the plugin properly after having built it ?



  • What do you mean "install properly" ?


  • Lifetime Qt Champion

    Are you sure that the plugin you modified was installed at the right location ?



  • Yes.

    It was installed under /usr/lib/qt5/plugins/audio


  • Lifetime Qt Champion

    On your target ?



  • Yes, of course.


  • Lifetime Qt Champion

    How big is your audio file ?



  • ~11 MB.

    Would you test it ?

    I have recompiled QtMultimedia without ALSA support and with PULSEAUDIO only.

    In /usr/lib/qt5/plugins/audio I have only libqtmedia_pulse.so

    Same thing when I launch my app again. libqtmedia_pulse.so plugin is loaded , and I have the same output as the one above...

    It really seems that something is wrecked under...


  • Lifetime Qt Champion

    I likely would (and already would have done it) but I don't have such a board at hand.

    And Rulseaudio is also working correctly ? (Without using Qt)



  • How can I test if pulseaudio is working fine ?


  • Lifetime Qt Champion

    I'd take a look at thist to check the setup.



  • @zyend - I know the topic is quite old, but could it be a simple explanation of a typo ?
    You have called the Audio component:
    id: audioPlayer
    and then try to play with:
    idPlayer.play()
    I think it should be:
    audioPlayer.play()

    Maybe I am reading the post wrong.



  • @zyend
    Although this is an old post, I ended up here Googling for the pulse audio initialization and someone else might do so too so here's important info for the solution of the problem.
    I too ran into issue that pulseaudio was no longer running since the

    QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)
    

    had been dropped from the code. This call apparently starts pulseaudio daemon (among other things).
    Returning it back fixed the issue.


  • Lifetime Qt Champion

    @OttoRyynanen Hi and welcome to devnet,

    Thanks for sharing your findings !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.