我是初学者,我创建了一个简单的媒体播放器,但问题是停止按钮不起作用。播放和暂停工作正常,但问题是只有停止按钮。点击停止按钮后音乐停止,但播放和暂停停止工作。
这是代码
public class MainActivity extends AppCompatActivity {
MediaPlayer mymediaplayer;
AudioManager myaudiomanager;
public void playme(View view) {
mymediaplayer.start();
}
public void pauseme(View view) {
mymediaplayer.pause();
}
public void stopme(View view) {
mymediaplayer.stop();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mymediaplayer=MediaPlayer.create(this,R.raw.music);
myaudiomanager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
int max=myaudiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int progress=myaudiomanager.getStreamVolume(AudioManager.STREAM_MUSIC);
SeekBar volumerocker=(SeekBar)findViewById(R.id.volume);
volumerocker.setMax(max);
volumerocker.setProgress(progress);
volumerocker.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
myaudiomanager.setStreamVolume(AudioManager.STREAM_MUSIC,i,0);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}