我正在使用VideoView播放实时流,并且它在大多数情况下都可以正常工作,但有时应用程序会冻结片刻并继续播放或崩溃并将我发送到主屏幕。
当我从列表视图中选择一个项目或点击KEY_DOWN / KEY_UP
:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if (mVideoView != null && mListView == null) {
if (listViewNext != listViewCurrent) { playChannel(listViewNext, 0); }
return true;
}
}
}
private void playChannel(int channel, int id) {
listViewCurrent = channel;
listViewNext = listViewCurrent + 1;
listViewPrev = listViewCurrent - 1;
if (mListViewChannels == "Danish") {
if (listViewNext >= arrayDanishChannels.size()) { listViewNext = 0; }
if (listViewPrev < 0) { listViewPrev = arrayDanishChannels.size() - 1; }
mListViewLink = arrayDanishLinks.get(listViewCurrent);
} else if (mListViewChannels == "World") {
if (listViewNext >= arrayWorldChannels.size()) { listViewNext = 0; }
if (listViewPrev < 0) { listViewPrev = arrayWorldChannels.size() - 1; }
mListViewLink = arrayWorldLinks.get(listViewCurrent);
}
String listViewName = (String) listView.getItemAtPosition(listViewCurrent);
String[] links = mListViewLink.split(";"); int temp = id + 1;
if (id < 0 || temp > links.length) { id = 0; temp = 1; }
mListViewLink = links[id]; listViewLinkId = temp; listViewLinkIds = links.length;
startVideo(listViewName+" ("+listViewLinkId+"/"+listViewLinkIds+")", mListViewLink);
mListViewCurrent = mListViewChannels;
}
private void startVideo(String title, String link) {
toastDisplay.cancel();
setInfoView(title);
imageView.setVisibility(ImageView.INVISIBLE);
videoView.removeCallbacks(videoRunnable);
videoView.stopPlayback();
MediaController media = new MediaController(MainActivity.this); media.setAnchorView(videoView); media.setMediaPlayer(videoView);
videoView.setMediaController(media);
videoView.setVideoPath(link);
videoView.setOnPreparedListener(videoViewPreparedListener);
videoView.setOnErrorListener(videoViewErrorListener);
videoView.setVisibility(VideoView.VISIBLE);
videoView.postDelayed(videoRunnable, videoViewTimeOut);
videoView.start();
mVideoView = "true";
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
SharedPreferences.Editor edit = pref.edit();
edit.putString("setLastStream", title+";"+mListViewChannels);
edit.apply();
}
private void setInfoView(String title) {
infoView.removeCallbacks(infoRunnable);
infoView.setText(title);
infoView.setVisibility(TextView.VISIBLE);
progressBar.setVisibility(ProgressBar.VISIBLE);
}
只需注意:我已经支付了流量,有些可以免费访问任何人,没有非法内容。
我使用的是带有固件4.4.2的Android机顶盒
我试图在任何地方添加try { .. } finally { .. }
,它有时会在随机时间冻结。
请帮助,我是新的制作应用程序,这真的让我发疯。
抱歉我的英语不好。