Important: Please read the Qt Code of Conduct -

Yocto + Qt5 + Alsa + RaspberryPi + USB Audio

  • I want to set up audio output for my raspberry pi with Yocto [2.6.1], I have configured Yocto in local.conf

    IMAGE_INSTALL_append = " gstreamer1.0  gstreamer1.0-meta-base gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer-plugins-ugly"
    IMAGE_INSTALL_append = " alsa-lib alsa-utils alsa-plugin alsa-tools"
    PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer alsa"

    When i test audio with aplay and wav file, i can heard sound (successfully).
    Then, i try to play trough Qt with QMediaPlayer (c++) and Audio QML, i can not heard anything and I got following message

    Could not open audio device for playback

    That my code:

    id: fileAudio
    source: "qrc:///Computer-Magic.mp3"
    onStatusChanged: testLabel.text = "File Audio Status: " + status + " - " + "Volume: " + volume
    onError: console.log(errorString)
    onBufferProgressChanged: console.log("Buffer Progress: "+ bufferProgress)
    onAvailabilityChanged: console.log("Availability: "+ availability)

    But, when I test with examples software from qt code (audiooutput), I can heard beep sound testing (the software have option to select audio device).
    I guess the problem is qt don't know which one audio device to use.

    How to set default audio device output globally in qt, so QMediaPlayer and QML Audio can run?


    That is result when i run my qt software

    root@raspberrypi0-wifi:~# ./QtTest
    Unable to query physical screen size, defaulting to 100 dpi.
    To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).
    Device name: "default"
    Device name: "default:CARD=Set"
    Device name: "sysdefault:CARD=Set"
    Device name: "front:CARD=Set"
    Device name: "surround21:CARD=Set,DEV=0"
    Device name: "surround40:CARD=Set,DEV=0"
    Device name: "surround41:CARD=Set,DEV=0"
    Device name: "surround50:CARD=Set,DEV=0"
    Device name: "surround51:CARD=Set,DEV=0"
    Device name: "surround71:CARD=Set,DEV=0"
    Device name: "iec958:CARD=Set,DEV=0"
    Warning: "Could not open audio device for playback."

  • Add pulseaudio in PACKAGECONFIG_append_pn-qtmultimedia and install pulseaudio and its tools in IMAGE_INSTALL

    Cleiton Bueno

    Blog | Linkedin | B2Open

  • This post is deleted!

  • @Cleiton-Bueno

    Thank for your reply.
    I'v tested with your suggestion before, but still problem. I got following message

    "PulseAudioService: pa_context_connect() failed"

    when i run

    ps -ae | grep pulseaudio


    opkg list-installed | grep pulse

    the result is nothing. maybe pulseaudio not completely installed.

  • @electronicsengineer8 check that DISTRO_FEATURES is with pulseaudio in the list and install the packages below in the IMAGE_INSTALL, something like below:

    DISTRO_FEATURES_append = "pulseaudio dbus systemd"
    IMAGE_INSTALL_append = "qtmultimedia qtmultimedia-plugins qtmultimedia-qmlplugins dbus pulseaudio-pulseaudio-server pulseaudio-misc pulseaudio-module-dbus-protocol alsa-utils"

    If using Systemd, add this below:
    PACKAGECONFIG_append_pn-pulseaudio = "systemd"

    Cleiton Bueno

    Blog | Linkedin | B2Open

  • @Cleiton-Bueno
    Thanks a lot, finally the audio device work like charm. I can hear the voice.

    I change pulseaudio-pulseaudio-server to pulseaudio-server.

    Then, a bit configuration after flashing because my system not run x11, That is the instruction

    Drl Sherif Omran
    I had the same issue yesterday, using Pulse audio for raspberrypi 0 W with DBus in a headless environment create with yocto without x11 and no systemd, you need to run and export dbus before you run pulseaudio.
    if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
         echo "Starting dbus" 
         export $(dbus-launch)
    In etc/pulse/client.conf, please enable allow-autospawn-for-root = yes
    Run pulseaudio -v to check if there's another problem in your config. Don't use --system switch because it won't be correct.
    pulseaudio -D --disallow-exit

Log in to reply