我正在开发 android 应用程序来播放直播。他们在 OS 2.2 和 2.3 上运行良好。给我们的新设备是 OS 4.0.4,每次我都会出错;onErrorListener() 方法中的媒体错误未知。这是我的代码
mVideoView = new VideoView(this);// (VideoView)
mVideoView.setId(id_mVideoview);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
mVideoView.setLayoutParams(lp);
mVideoView.setOnKeyListener(this);
mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
mHandler.removeCallbacksAndMessages(null);
Toast.makeText(
streamplayer_filmstrip.this," Video cannot be played", Toast.LENGTH_LONG)
.show();
try {
Thread.sleep(3000);
Go_Back();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Log.d("VidError",
"Exception :: " + e.toString() + e.getMessage());
Toast.makeText(streamplayer_filmstrip.this,
"On Error Ex ::" + e.toString(), Toast.LENGTH_LONG)
.show();
e.printStackTrace();
}
return true;
}
});
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
// doneSomething
});
mVideoView.setVideoURI(Uri.parse(getStreamURL("some_url_for_live_stream")));
mVideoView.postInvalidateDelayed(100);
mVideoView.setMediaController(null);
if (mView1.getVisibility() == View.GONE)
mVideoView.requestFocus();
else {
ll_PopUp.bringToFront();
mView1.requestFocus();
}
mVideoView.start();
非常感谢任何帮助