Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt 6.5.3 on Android: No audio device detected
Forum Updated to NodeBB v4.3 + New Features

Qt 6.5.3 on Android: No audio device detected

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
andriodqt 6.5.3c++audio
1 Posts 1 Posters 981 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheoSys
    wrote on last edited by
    #1

    In my application I try to play some small WAV files. The code I wrote works on all operating systems except on Android. There I get the following error at the moment the audio file should be played:

    W/TPanel  : java.lang.NullPointerException: Attempt to invoke virtual method 'android.media.AudioDeviceInfo[] android.media.AudioManager.getDevices(int)' on a null object reference
    W/TPanel  : 	at org.qtproject.qt.android.multimedia.QtAudioDeviceManager.getAudioDevices(QtAudioDeviceManager.java:181)
    W/TPanel  : 	at org.qtproject.qt.android.multimedia.QtAudioDeviceManager.getAudioOutputDevices(QtAudioDeviceManager.java:74)
    W/TPanel  : 
    W/TPanel  : No audio device detected
    

    Here is the code snipped used to play the file:

    #include <QtMultimediaWidgets/QVideoWidget>
    #include <QtMultimedia/QMediaPlayer>
    #include <QAudioOutput>
    #include <QMediaMetaData>
    #include <QMediaFormat>
    #include <QMediaDevices>
    
    /* ... */
    
    void MainWindow::playSound(const string& file)
    {
        qtDebug() << "Playing file " << file;
    
        if (!mMediaPlayer)
        {
            mMediaPlayer = new QMediaPlayer(this);
            mAudioOutput = new QAudioOutput(this);
            mMediaPlayer->setAudioOutput(mAudioOutput);
            connect(mMediaPlayer, &QMediaPlayer::playingChanged, this, &MainWindow::onPlayingChanged);
            connect(mMediaPlayer, &QMediaPlayer::durationChanged, this, &MainWindow::onDurationChanged);
            connect(mMediaPlayer, &QMediaPlayer::metaDataChanged, this, &MainWindow::onMetaDataChanged);
            connect(mMediaPlayer, &QMediaPlayer::mediaStatusChanged, this, &MainWindow::onMediaStatusChanged);
            connect(mMediaPlayer, &QMediaPlayer::errorOccurred, this, &MainWindow::onPlayerError);
        }
    
        mMediaPlayer->setSource(QUrl::fromLocalFile(QString::fromStdString(file)));
    
        if (!mMediaPlayer->isAvailable())
        {
            qtDebug() << "WARNING: No audio modul found!";
            return;
        }
    
        if (mMediaPlayer->isPlaying())
        {
            mMediaPlayer->stop();
            mMediaPlayer->setPosition(0);
        }
    
        mMediaPlayer->play();
    }
    

    In header file the class is defined. Here a shortened excerpt:

    #include <QMainWindow>
    #include <QMediaPlayer>
    
    class QAudioOutput;
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
        public:
            MainWindow();
            ~MainWindow();
    
        private slots:
            void onDurationChanged(qint64 duration);
            void onMetaDataChanged();
            void onPlayingChanged(bool plying);
            void onPlayerError(QMediaPlayer::Error error, const QString &errorString);
            void onMediaStatusChanged(QMediaPlayer::MediaStatus status);
    
        private:
            void playSound(const std::string& file);
            void stopSound();
            void muteSound(bool state);
            void setVolume(int volume);
    
            QMediaPlayer *mMediaPlayer{nullptr};
            QAudioOutput *mAudioOutput{nullptr};
    }
    

    I tried the player example and it worked. The code I wrote is based on the example. I checked the permissions and other settings and compared it with the example, but don't see any significant difference. Because the example works, the error must be in my code. But where?

    A.T.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved