我正在开发一个简单的广播流应用程序来使用 URL 播放广播。此应用程序在除 V>=4.0 之外的所有版本中运行
有没有人对此有任何想法。
initializeUIElements();
StartPlaying();
private void initializeUIElements() {
buttonPlay = (ImageView) findViewById(R.id.buttonPlay);
buttonPlay.setOnClickListener(this);
playSeekBar=(ProgressBar)findViewById(R.id.progressBar1);
}
private void startPlaying() {
initializeMediaPlayer();
player.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
Log.i("on prepared", "on prepared");
mp.start();
}
});
player.setOnErrorListener(new OnErrorListener(){
public boolean onError(MediaPlayer arg0, int arg1,
int arg2) {
Toast.makeText(getApplicationContext(),"An error happened while preparing radio",Toast.LENGTH_LONG).show();
player.reset();
initializeMediaPlayer();
return false;
}
});
private void initializeMediaPlayer() {
player = new MediaPlayer();
player.reset();
try {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://***************");
player.prepareAsync();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
player.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.i("percent", ""+percent);
if( (percent!=0)||(percent==100) )
{
playSeekBar.setVisibility(View.INVISIBLE);
buttonPlay.setVisibility(View.VISIBLE);
}
}
});
在 Android 4.0 版中,它给出的错误如下:
11-23 13:06:37.329: E/MediaPlayer(4011): Error (1,-2147483648)
并且 Player.bufferingUpdateListener() 没有被调用。在这里它只是显示 playeekbar 旋转和旋转.. 请帮助解决这个问题。