播放器播放后如何在没有任何缓冲的情况下流式传输在线广播。它应该缓冲几秒钟以继续播放收音机,但它会卡住几秒钟然后播放。
我的Aync任务: class Player扩展AsyncTask { 私人ProgressDialog进展;
@Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
Boolean prepared;
try {
mediaPlayer.setDataSource(params[0]);
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
intialStage = true;
playPause = false;
control.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
mediaPlayer.reset();
}
});
mediaPlayer.prepare();
prepared = true;
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
Log.d("IllegarArgument", e.getMessage());
prepared = false;
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
prepared = false;
e.printStackTrace();
}
return prepared;
}
@Override
protected void onPostExecute(Boolean result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
if (progress.isShowing()) {
progress.cancel();
}
Log.d("Prepared", "//" + result);
mediaPlayer.start();
media.stop();
intialStage = false;
}
public Player() {
progress = new ProgressDialog(MainActivity.this);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
this.progress.setMessage("Buffering...");
media.start();
}
}
public void mute1(View v){
speaker.setVisibility(View.VISIBLE);
mute.setVisibility(View.INVISIBLE);
mediaPlayer.setVolume(0,0);
media.setVolume(0,0);
seekbar.setClickable(false);
seekbar.setFocusable(false);
seekbar.setEnabled(false);
}
public void speaker1(View v){
speaker.setVisibility(View.INVISIBLE);
mute.setVisibility(View.VISIBLE);
mediaPlayer.setVolume(1,1);
media.setVolume(1,1);
seekbar.setClickable(true);
seekbar.setFocusable(true);
seekbar.setEnabled(true);
}
如何在播放器启动后让我的播放器为在线电台做准备而不进行任何流媒体播放。
请帮助我..
我的来源是:
if (playPause) {
control.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
new Player().cancel(true);
media.stop();
media.reset();
mediaPlayer.reset();
if (mediaPlayer.isPlaying())
mediaPlayer.stop();
mediaPlayer.reset();
media.stop();
playPause = false;
} else {
control.setBackgroundResource(R.drawable.pause);
if (intialStage) {
new Player()
.execute("http://streaming.shoutcast.com/MUKILFMRADIO");
} else {
if (!mediaPlayer.isPlaying())
mediaPlayer.start();
}
}
playPause = true;
}
};
答案 0 :(得分:0)
我建议使用Exoplayer而不是媒体播放器.ExoPlayer是适用于Android的应用级媒体播放器。它提供了Android的MediaPlayer API的替代方案,用于在本地和通过Internet播放音频和视频。 ExoPlayer支持Android的MediaPlayer API目前不支持的功能,包括DASH和 SmoothStreaming 自适应回放。与MediaPlayer API不同,ExoPlayer易于定制和扩展,并且可以通过Play商店应用程序更新进行更新。这个链接可以让您更好地了解Exoplayer。
https://developer.android.com/guide/topics/media/exoplayer.html