Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. QtonPi
  4. Get sound from jack with QMediaPlayer or omxplayer system calls?

Get sound from jack with QMediaPlayer or omxplayer system calls?

Scheduled Pinned Locked Moved Solved QtonPi
5 Posts 3 Posters 2.7k 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.
  • D Offline
    D Offline
    davidino
    wrote on 2 Jun 2018, 14:10 last edited by davidino 6 Feb 2018, 14:11
    #1

    Goodmorning,
    I've downloaded meta-boot2qt and built for Raspberrypi3.
    I'm trying to get audio from raspberry jack output.
    At the current state I can play songs from terminal with "omxplayer -o local music.mp3" getting sound from jack, on the other side with commands like "omxplayer -o alsa " or omxplayer -o hdmi", I get audio from hdmi.
    I succeded to play music with QMediaPlayer (both in c++ or qml), but I'm not able to get it from jack.
    Below the code used in c++:

        QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
        foreach (QAudioDeviceInfo i, devices){
            qDebug()<<i.deviceName()<<endl;
        }
    
    
    
        QMediaPlayer *playMusicObj = new QMediaPlayer();
        playMusicObj->setMedia(QUrl::fromLocalFile("/home/davide/music.mp3"));
        QMediaService *svc = playMusicObj->service();
        if (svc != nullptr)
        {
            QAudioOutputSelectorControl *out = qobject_cast<QAudioOutputSelectorControl *>
                                               (svc->requestControl(QAudioOutputSelectorControl_iid));
            if (out != nullptr)
            {
    
                out->setActiveOutput(devices.at(0).deviceName());
                svc->releaseControl(out);
            }
        }
        playMusicObj->setVolume(1);
        playMusicObj->play();
    

    Whatever devicesName I use, the audio always comes from hdmi.
    I also tested the example multimedia-> audioutput among the qt example code, but the result is the same, the audio always come from hdmi.

    I wonder if omxplayer is the only solution as they did in the following link:
    http://www.raspberry-projects.com/pi/programming-in-c/audio/playing-audio

    I'd prefer to stay with QMediaPlayer because it offers much more possibilities than system calls.
    Can you help me?

    Than you for the attention

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davidino
      wrote on 12 Aug 2020, 15:15 last edited by
      #5

      Found the solution for I2S, maybe it can work for jack output here:
      https://forum.qt.io/topic/117721/getting-sound-from-jack-with-alsa-instead-of-pulseaudio/2

      1 Reply Last reply
      1
      • K Offline
        K Offline
        Kernel KIM
        wrote on 22 Sept 2018, 05:36 last edited by
        #2

        Hi!!

        Did you solve your problem?
        I also met same problem. If you solved it, please share your solutions.

        Thanks,

        1 Reply Last reply
        0
        • E Offline
          E Offline
          etiennedm
          wrote on 21 Nov 2018, 16:53 last edited by
          #3

          Hi @davidino, @Kernel-KIM

          Did you solve your problem?
          I also met same problem.
          I use debian stretch and Qt 5.11. Even after setting up all possible flags on rpi3, I can't get the sound out from the jack in my Qt app. Command line tests play sound through jack....

          AND : If I boot without HDMI cable, sound goes out from jack, even after pluging it into rasp and displaying qt app.

          Thanks !

          1 Reply Last reply
          0
          • D Offline
            D Offline
            davidino
            wrote on 29 Dec 2018, 10:17 last edited by
            #4

            Hello @Kernel-KIM and @etiennedm ,
            no, I haven't solved the problem. In my opinion the only solution that could work is extracting the I2S signal from HDMI, and get the sound from it.
            After all, the raspberry cape use this approach.

            Regards,
            Davidino

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davidino
              wrote on 12 Aug 2020, 15:15 last edited by
              #5

              Found the solution for I2S, maybe it can work for jack output here:
              https://forum.qt.io/topic/117721/getting-sound-from-jack-with-alsa-instead-of-pulseaudio/2

              1 Reply Last reply
              1

              • Login

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