收音机应该启动,但是我在终端收到 E / MediaPlayer:暂停状态为0
我不完全知道该怎么做。以前是应该设置字幕控制器的问题,但是它消失了,我只有状态0和状态1的问题
b_play = (Button) findViewById(R.id.b_play);
b_play.setEnabled(false);
b_play.setText("LOADING");
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
new PlayerTask().execute(stream);
b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (started) {
started = false;
mediaPlayer.pause();
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("PAUSE");
}
}
});
}
class PlayerTask extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... strings) {
try {
mediaPlayer.setDataSource(strings[0]);
mediaPlayer.prepare();
prepared = true;
} catch (IOException e) {
e.printStackTrace();
}
return prepared;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
mediaPlayer.start();
b_play.setEnabled(true);
b_play.setText("PLAY");
}
}