Results 1 to 4 of 4

Thread: Use of audio jack buttons

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Use of audio jack buttons

    Hi,
    I need an external hardware button to start a function of my app.

    Do you have an idea if (or how) Qt is able to detect the pressing of an audio jack button like this one here?
    https://www.gearbest.com/cables-adapter/pp_58618.html

    Cheers,
    Sebastian

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,709
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Use of audio jack buttons

    Qt can't do that.
    Its a hardware driver issue.
    Once you have a driver that can deliver system events when the button is pressed, depending on the events type you might catch it with Qt.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    sedi (8th September 2017)

  4. #3
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Use of audio jack buttons

    I see what you mean. Shoot. Okay, I think I might be able to solve my (special) use case with an external microphone, being briefly switched on via a hardware button - and an audioInput that waits for a level bigger than a certain threshold to trigger the action. "AudioInput" Qt example seems a good starting point to me. Cumbersome for many use cases, okay for mine. Thank you!

  5. #4
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Use of audio jack buttons

    Ok, I've got it to work. If you wanna do that on a tablet, be aware that you've got to trick the device into believing there's an actual headset. I've done that with two 32 Ohm resistors (R & L to Ground) and a cheap 1$ electret mic capsule like this: inputSwitch.png


    After that, you can use the Qt AudioInput example for the detection.
    Just check for the audio level in "AudioInput::refreshDisplay()" for starters.
    Qt Code:
    1. if (m_audioInfo->level() > yourThreshold) { ... }
    To copy to clipboard, switch view to plain text mode 
    Consider blocking your detection for a certain amount of time after a trigger impulse, to prevent double/multiple triggering by contact chatter.

    Please note that the mic's circuit must be closed when you insert the headset jack into the device. After insertion, you can leave it open (just close it to trigger what you want to trigger), but you need to convince the device of seeing a headset while connecting. This applies to Android at least. On a windows laptop it was enough to just short-circuit the mic input for triggering.

    All this is barely a Qt topic after all, but it might help Qt users that come with similar intentions of finding a switch/trigger possibility.

Similar Threads

  1. usb audio help
    By K4ELO in forum Qt Programming
    Replies: 3
    Last Post: 13th February 2013, 16:13
  2. mp3 audio recording
    By dhe in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2012, 10:00
  3. play audio url
    By tungvc in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2010, 11:04
  4. Audio Recording in qt
    By BalaQT in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2009, 09:01
  5. input audio
    By addu in forum Qt Programming
    Replies: 9
    Last Post: 10th September 2009, 11:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.