0

I have a service with MediaPlayer in it. From Activity I need to change Player's volume. Any ideas? P.S. I very need your help P.P.S. Sorry for my English, please

Helisia
  • 568
  • 2
  • 7
  • 23
  • @Rani, yes, I'm using SeekBar in Activity. In it's listener, in onStopTrackingTouch() I need to change the volume of MediaPlayer – Helisia Oct 19 '13 at 07:22

2 Answers2

1

This might help you..

protected static void setVolume(int volume) {
        currentVolume = volume;
        {
            if (volume == 1) {
                volume = 2;
            }
            try {
                float vol = ((float) volume / CONSTANT.SYSTEM_MAX_VOLUME);
                mediaPlayer.setVolume(vol, vol);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

Also refer this

Community
  • 1
  • 1
SweetWisher ツ
  • 7,296
  • 2
  • 30
  • 74
1

If it is a local Service and you have not forced it to run into another thread, you can define a method to set the MediaPlayer's volume, bind to the Service from the Activity, and call the method directly. See the "Local Service Sample" here to see how to bind to a Service. Once you have bound to the Service, you can cast the IBinder you receive to an instance of your Service class to use its methods.

If it is not a local Service or if you have made it run in a separate thread, you will need to communicate with the Service via a Messenger/Handler or using an Intent. There is a "Remote Messenger Service Sample" in the same link from before.

Dave
  • 4,282
  • 2
  • 19
  • 24