Im streaming an mp3 audio from a url by using mediaplayer, Now im able to play music , But when i select seekbar at a random position, music getting stopped and the below exception and warning occurs
W/MediaPlayer: info/warning (703, 0)
W/MediaPlayer: info/warning (702, 0)
W/MediaPlayer: info/warning (701, 0)
W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
. can anyone pls help me to resolve my issue. thank you.
My Code is :
private ImageView play, forward, backward;
private MediaPlayer mediaPlayer;
private boolean playing = false;
private ProgressDialog dialog;
private String mp3link;
private SeekBar seekbar;
private Handler handler = new Handler();
private int mediaPos;
private int mediaMax;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String url ="";
initWidgets();
}
private void initWidgets() {
mp3link = "http://loc8app.com/church/uploads/audio/749928ad6fcb7b1aceefdf03bd7a9465.mp3";
play = (ImageView) findViewById(R.id.control);
seekbar = (SeekBar) findViewById(R.id.seekBar);
// forward = (ImageView) findViewById(R.id.playeer_forward);
// backward = (ImageView) findViewById(R.id.playeer_back);
mediaPlayer = new MediaPlayer();
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
playFunction();
}
});
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(mediaPlayer != null && fromUser){
mediaPlayer.seekTo(progress);
}
}
});
}
private void playFunction() {
if (!playing) {
try {
dialog = ProgressDialog
.show(MainActivity.this,
"",
getString(com.root5solutions.music.R.string.buffering),
true);
dialog.setCancelable(true);
dialog.show();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(mp3link);
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
play.setBackgroundResource(R.drawable.pause);
playing = true;
//this is new
mediaPos = mp.getCurrentPosition();
mediaMax = mp.getDuration();
seekbar.setMax(mediaMax);
seekbar.setProgress(mediaPos);
//this line is the error
handler.removeCallbacks(moveSeekBarThread);
handler.postDelayed(moveSeekBarThread, 100);
mp.start();
dialog.dismiss();
}
});
mediaPlayer.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
dialog.dismiss();
}
} else {
play.setBackgroundResource(R.drawable.play);
mediaPlayer.stop();
mediaPlayer.release();
playing = false;
}
}
@Override
public void onBackPressed() {
super.onBackPressed();
if (mediaPlayer.isPlaying()) {
handler.removeCallbacks(moveSeekBarThread);
mediaPlayer.stop();
mediaPlayer.release();
}
}
private Runnable moveSeekBarThread = new Runnable() {
public void run() {
if (mediaPlayer.isPlaying()) {
int mediaPos_new = mediaPlayer.getCurrentPosition();
int mediaMax_new = mediaPlayer.getDuration();
seekbar.setMax(mediaMax_new);
seekbar.setProgress(mediaPos_new);
handler.postDelayed(this, 1000); // Looping the thread after 1 second
}
}
};
}
Logcat Shows :
W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:48.343 23176-23236/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:48.974 23176-23192/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:49.384 23176-23700/com.root.music W/MediaPlayer: info/warning (703, 0)
11-15 14:15:49.384 23176-23700/com.root.music W/MediaPlayer: info/warning (701, 0)
11-15 14:15:49.584 23176-23394/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:50.375 23176-23193/com.root.music W/MediaPlayer: info/warning (703, 0)
11-15 14:15:50.375 23176-23236/com.root.music W/MediaPlayer: info/warning (702, 0)
11-15 14:15:51.176 23176-23700/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:51.777 23176-23236/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:52.387 23176-23192/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:52.988 23176-23394/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:53.588 23176-23193/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:54.189 23176-23700/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
11-15 14:15:54.809 23176-23236/com.root.music W/MediaHTTPConnection: readAt 2230281 / 32768 => java.net.ProtocolException
try this:
mediaPlayer.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
@Override
public void onSeekComplete(MediaPlayer arg0) {
Log.d(TAG, "onSeekComplete() current pos : " + arg0.getCurrentPosition());
SystemClock.sleep(200);
mediaPlayer.start();
}
});
来源:https://stackoverflow.com/questions/40605675/android-mediaplayer-info-warning-703-0-info-warning-702-0-info-warning