如何避免在mediaplayer.prepare时延迟吐司,我想在btn onclick时显示吐司。
FloatingActionButton button = findViewById(R.id.playbtnnine);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mediaPlayer.isPlaying()){
mediaPlayer.reset();
Toast.makeText(getBaseContext(), "Stop" , Toast.LENGTH_SHORT ).show();
}else {
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setLooping(true);
mediaPlayer.start();
Toast.makeText(getBaseContext(), "Loading" , Toast.LENGTH_SHORT ).show();
}
}
});
答案 0 :(得分:-1)
您应该尝试
FloatingActionButton button = findViewById(R.id.playbtnnine);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getBaseContext(), "Loading" , Toast.LENGTH_SHORT ).show();
if (mediaPlayer.isPlaying()){
mediaPlayer.reset();
Toast.makeText(getBaseContext(), "Stop" , Toast.LENGTH_SHORT ).show();
}else {
try {
mediaPlayer.setDataSource(url);
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setLooping(true);
mediaPlayer.start();
}
}
});