Forums

OverviewV-Play 2 Support (Qt 5) › Android Hardware Volume Buttons

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9771

    Alec

    Hi,

     

    Is there any way to force the Android hardware volume buttons to control the media volume. Something like the native call

     

    setVolumeControlStream(AudioManager.STREAM_MUSIC)

     

    If a sound effect is playing in my game, the volume buttons control the media volume. However, if no sound effect is playing, the buttons control the ringtone volume. As I’m only using very short sound effects it is very difficult to control the volume and users won’t know to press the buttons when a sound is playing.

     

    This was tested on a device running Lollipop and it also happens in the AudioTest example (it makes more sense in that context though).

     

    Any help would be much appreciated.

     

    alb

    #9818

    Günther
    V-Play Team

    Hi alb!

    Sadly, we never encountered a use-case where we had to change this setting with Qt/Qml up until now … maybe you can get an answer on how to do it at the official Qt/Qml support forums.

    In case you do not find a good answer, I tried to solve your problem by using a little “hack”:
    At least for my android phone and the current qt version, it works if a muted sound is played endlessly in the background of the app. The device is then tricked into thinking that music is playing and lets you control the media volume. (even though nothing can actually be heard)

    This is how I did it:

    import QtMultimedia 5.0
    
    // ...
    
    Scene {
    
    
        BackgroundMusic {
          id: muted_loop
          loops: SoundEffect.Infinite
          muted: true
          source: "../assets/Click1.wav"
        }
    
        // ...
    }
    
    // ...

     

    Cheers,

    GT

     

     

     

     

    #9820

    Alec

    Thanks for getting back to me. Your workaround seems like a decent solution, I’ll give it a try.

     

    If the qt forums have a better answer, I’ll post it here.

Viewing 3 posts - 1 through 3 (of 3 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support