Change volume on a select mediaplayer with seekbar?

All your problems with Audio, Video and Images.

Change volume on a select mediaplayer with seekbar?

Postby waarez » Fri Apr 22, 2011 7:55 pm

Hi,

I'm writing a DJ panel for android. When my app starts up, it creates 2 different media players.
I have 2 seekbars which I need to use for those multiplayers.

I have tried to use the following code for the mediaplayer on the left side of my dj panel:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         leftAm = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
  2.         int maxVolume = leftAm.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  3.         int curVolume = leftAm.getStreamVolume(AudioManager.STREAM_MUSIC);
  4.         SeekBar volControl = (SeekBar)findViewById(R.id.leftVolume);
  5.         volControl.setMax(maxVolume);
  6.         volControl.setProgress(curVolume);
  7.         volControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  8.  
  9.             @Override
  10.             public void onStopTrackingTouch(SeekBar arg0) {
  11.              // TODO Auto-generated method stub
  12.             }
  13.        
  14.             @Override
  15.             public void onStartTrackingTouch(SeekBar arg0) {
  16.              // TODO Auto-generated method stub
  17.             }
  18.            
  19.             @Override
  20.             public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
  21.              // TODO Auto-generated method stub
  22.              leftAm.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
  23.             }
  24.            });  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


This works, but the problem is that the left volume seekbar also interferes with the volume of the right sided mediaplayer. This is because of the AudioManager.STREAM_MUSIC. This function takes all the audiostreams and so when I change the volume, it just changes the volume of everything.

Can anyone help me on this issue so I can seperatly change the volume of my left and my right mediaplayer?
waarez
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Apr 22, 2011 7:46 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 7 guests