Phonon BackendCapabilities::availableAudioOutputDevices() returns empty list

Harald Sitter sitter.harald at gmail.com
Wed Dec 18 18:24:58 GMT 2013


Moin,

On Wed, Dec 18, 2013 at 5:56 PM, Christian Esken <esken at kde.org> wrote:
> Hello,
>
> I am trying to find the existing audio devices known to Phonon. I am trying
> to use BackendCapabilities::availableAudioOutputDevices() in KDE4.11.3, but
> this simply returns an empty list. "kcmshell4 kcm_phonon" shows all devices,
> so its not a generic issue. As background information, I want to get the
> actual device name from Phonon, and then match it to the Mixer devices in
> KMix (e.g. "hw:0 => hw:0" in ALSA or "/dev/dsp1 => /dev/mixer1"  in OSS).
> Do I need initialization code (the tutorials made me think that I do not
> need it)? Does anybody has advice?
>
>   Christian
>
>
> // This is the first Phonon call in my code:
>         QList<Phonon::AudioOutputDevice> devs =
> Phonon::BackendCapabilities::availableAudioOutputDevices();
>         if (devs.isEmpty())
>             return;   // Always returns!!!
>
>         Phonon::AudioOutputDevice& dev = devs[0];
> // ...

Like most things in Phonon, device listing is async, so particularly
after startup you can get an empty list. You want to connect to the
availableAudioCaptureDevicesChanged signal so that you get the list
whenever it changes.

quick demo:


#include <QApplication>
#include <QDebug>

#include <phonon/BackendCapabilities>

using namespace Phonon;

class Foo : public QObject
{
    Q_OBJECT
public slots:
    void devicesChanged() {
        QList<Phonon::AudioOutputDevice> devs =
Phonon::BackendCapabilities::availableAudioOutputDevices();
        if (devs.isEmpty())
            qDebug() << "empty";
        else
            qDebug() << "not empty";
    }
};

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    Foo foo;
    QObject::connect(Phonon::BackendCapabilities::notifier(),
SIGNAL(availableAudioCaptureDevicesChanged()),
                     &foo, SLOT(devicesChanged()));
    foo.devicesChanged(); // Query right after connect to make sure
the signal wasn't emitted before the connect.
    return app.exec();
}

#include "videoplay.moc"


HS



More information about the kde-multimedia mailing list