[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    Re: Phonon BackendCapabilities::availableAudioOutputDevices() returns empty list
From:       Harald Sitter <sitter.harald () gmail ! com>
Date:       2013-12-18 18:24:58
Message-ID: CAEc+18GAy4twGPFN7VWCP7Jf7-xv=aVAYQNiRyJxPdtYDOM6PQ () mail ! gmail ! com
[Download RAW message or body]

Moin,

On Wed, Dec 18, 2013 at 5:56 PM, Christian Esken <esken@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
_______________________________________________
kde-multimedia mailing list
kde-multimedia@kde.org
https://mail.kde.org/mailman/listinfo/kde-multimedia
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic