私のアプリでラジオストリーミングを統合しようとしましたが、うまく機能せず、理由がわかりません。 私のウェブラジオのリンクです:https://www.radioking.com/widgets/player/player.php?id=480&c=%23f39c12&ii=&p=1&pp=1&i=1&eq=1&po=1&t=1&a=1&f=bigAndroidでラジオストリーミングを作成する方法
私を助けることができますか? これは私のコードです:
public class MainActivity extends AppCompatActivity {
private Button btn;
private boolean playPause;
private MediaPlayer mediaPlayer;
private ProgressDialog progressDialog;
private boolean initialStage = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.audioStreamBtn);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
progressDialog = new ProgressDialog(this);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!playPause) {
btn.setText("Pause Streaming");
if (initialStage) {
new Player().execute("https://www.radioking.com/widgets/player/player.php?id=480&c=%23f39c12&ii=&p=1&pp=1&i=1&eq=1&po=1&t=1&a=1&f=big");
} else {
if (!mediaPlayer.isPlaying())
mediaPlayer.start();
}
playPause = true;
} else {
btn.setText("Launch Streaming");
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
}
playPause = false;
}
}
});
}
@Override
protected void onPause() {
super.onPause();
if (mediaPlayer != null) {
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
}
}
class Player extends AsyncTask<String, Void, Boolean> {
@Override
protected Boolean doInBackground(String... strings) {
Boolean prepared = false;
try {
mediaPlayer.setDataSource(strings[0]);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
initialStage = true;
playPause = false;
btn.setText("Launch Streaming");
mediaPlayer.stop();
mediaPlayer.reset();
}
});
mediaPlayer.prepare();
prepared = true;
} catch (Exception e) {
Log.e("MyAudioStreamingApp", e.getMessage());
prepared = false;
}
return prepared;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if (progressDialog.isShowing()) {
progressDialog.cancel();
}
mediaPlayer.start();
initialStage = false;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.setMessage("Buffering...");
progressDialog.show();
}
}
}
タイトルにALL CAPSを使用しないでください.YELLINGと同じとみなされます。 – jmoerdyk