Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Return system (media) volume

Hi,

Errm might be a silly question, but how do i return the system media volume? The one you get when your in the app playing back a file and you use the volume controls on the side. I've got a looping sound object and getVolume() returns the volume value of that object (which defaults to 0.5). I see that Ti.Media has a property volume but that seems to return nothing (at least i get no exceptions or anything when i call it in an alert). The api docs don't return anything else for "volume" and i really need to be able to control this (i would be very surprised and disappointed if i could not)

— asked September 21st 2010 by Alex Borisov
  • android
  • media
  • mobile
  • volume
  • win32
1 Comment
  • bump!

    — commented April 27th 2011 by Max Finnsjö

2 Answers

  • I dont know if there exists some other way, but I wrote a micro-module for Android that handles the volume stuff… I used it to make up a custom slider that works in sync with volume hardware buttons…

    If interested, write to annakozy2007(at)gmail.com… or you can write it yourself, it's really small and it's my first module whatsoever :)))

    It uses AudioManager class like this (read the API for AudioManager in developer.android.com):

    
    private AudioManager audio;
    public VolumeModule(TiContext tiContext) {
            super(tiContext);
            audio = (AudioManager) tiContext.getActivity().getSystemService(Context.AUDIO_SERVICE);
        }
    
        // Methods
    @Kroll.method
    public void volumeUp() {
        Log.d(LCAT, "volume up");
        audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                   AudioManager.ADJUST_RAISE,1);
    }
    

    etc.

    — answered May 7th 2011 by Ganna Kozynenko
    permalink
    1 Comment
    • could you please share me the module-code ? i´m really interessted about it …

      — commented May 15th 2013 by Oli S.
  • hey i need some help !
    I search like something like your code you post !

    I want to modified Media Control for using inside Titanium !
    So I have to (play/pause/back-forward/vol-up/down) code … could you post you module sources / eg. link me
    your packed sources (module) ?

    also i need to route sound (android) to titanium socket stream (does i need also module java code ? )

    — answered October 31st 2012 by Oli S.
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.