package com.zakilive.sounddemo; import android.content.Context; import android.media.AudioManager; import android.media.MediaPlayer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.log; import android.view.View; import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChnageListener; import java.util.Timer; import java.util.TimerTask; Public class MainActivity extends AppCompatActivity{ MediaPlayer mtemplayer; AudioManager audioManager; public void playAudio(View view){ mtemplayer.start(); } public void pauseAudio(View view) { mtemplayer.pause(); } protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceSTate); setContentView(R.activity_main); mtemplayer = MediaPlayer.create(this,R.id.laugh); audioManager = (AudioManager) getSystemService(Context,AUDIO_SERVICE); int maxVolume = audioManager.getStreamMaxVolume(Audiomanager,STREAM_MUSIC); int currentVolume= audioManager.getSteamVolume(AudioManager,STREAM_MUSIC); SeekBar volumeControl = (SeekBar) findViewById(R.id.seekBar); volumeControl.setMax(maxVolume); volumeControl.setProgress(currentVolume); volumeControl.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){ @Override public void onStartTrackingTouch(SeekBar seekBar){ } @Override public void onStopTrackingTouch(SeekBar seekBar) { } public void onProgressChnaged(SeekBar seekBar,int progress,boolean fromUser) { Log.i("SeekBar value",Integer.toString(progress)); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,progress,0); } }); final SeekBar scrubber = (SeekBar) findViewById(R.id.scrubber); scrubber.setMax(mtemplayer.getDuration()); new Timer().scheduleAtFixedRate(new TimerTask(){ public void run() { scrubber.setProgress(mtemPlayer.getCurrentPosition()); } },0,1000); scrubber.setOnSeekBarChanegListener(new OnSeekBarChangeListener()){ @Override public void onProgressChange(SeekBar seekBar,int Progress, boolean fromUser){ mtemPlayer.seekTo(progress); } @override public void onSTartTrackingTouch(SeekBar seekBar){ } @Override public void onSTopTrackingTouch(SeekBar seekBar) { } }); } }