Show Media Volume Slider on the UI

弘承业
2023-12-01

  leftAm = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    int maxVolume = leftAm.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int curVolume = leftAm.getStreamVolume(AudioManager.STREAM_MUSIC);
    SeekBar volControl = (SeekBar)findViewById(R.id.leftVolume);
    volControl.setMax(maxVolume);

    volControl.setProgress(curVolume);
    volControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {


    @Override
    public void onStopTrackingTouch(SeekBar arg0) {
     // TODO Auto-generated method stub
    }

    @Override
    public void onStartTrackingTouch(SeekBar arg0) {
     // TODO Auto-generated method stub
    }

    @Override
    public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
     // TODO Auto-generated method stub
     leftAm.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
    }
   });  

xml:

<SeekBar
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/volumebar"
            android:max="100"
            android:paddingBottom="10dip"/>

http://stackoverflow.com/questions/9488117/android-show-media-volume-slider-on-the-ui

 类似资料:

相关阅读

相关文章

相关问答