0
我有一個全屏的視頻視圖,並且想按某個鍵時觸發popupMenu。日誌顯示關鍵事件被捕獲,但彈出視圖不會顯示。任何想法爲什麼?爲什麼popUpMenu不能在KeyEvent上顯示?
@Override
public boolean onKeyDown(int keyCode , KeyEvent event){
switch(keyCode){
case KeyEvent.KEYCODE_DPAD_CENTER:
Log.i("POP uP MENU","Show");
mVideoView.pause();
showPopupMenu(new View(VideoPlayer.this));
case KeyEvent.KEYCODE_D:
popupMenu.dismiss();
}
return true;
}
private void showPopupMenu(View v){
popupMenu = new PopupMenu(VideoPlayer.this, v);
if(bitRates != null){
for(int i=0;i<bitRates.size();i++){
int menuItem = i;
popupMenu.getMenu().add(0,menuItem, 0,qualityList.get(i)+" : "+bitRates.get(i));
}
}
popupMenu.show();
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem item) {
progressDialog = ProgressDialog.show(VideoPlayer.this, "", "Loading video...");
final int position = mVideoView.getCurrentPosition();
new Thread() {
public void run() {
try{
runOnUiThread(new Runnable() {
public void run() {
play(streamUrls.get(item.getItemId()),position);
}
});
}
catch (Exception e)
{
Log.e("tag", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
return true;
}
});
}
沒關係解決了這個問題..謝謝。 – Fabii 2012-04-02 16:16:59
小心分享你如何修復它? – Joeblackdev 2012-04-02 17:10:42
@Joeblackdev,是的,似乎KeyEvent.KEYCODE_DPAD_CENTER是默認情況下由VideoView觸發的事件。所以當我按下該鍵時,VideoView觸發了它的事件事件,而不是我要求的事件。我將KeyEvent KEYCODE更改爲另一個鍵(Videoview未使用的鍵),並且它工作正常。 – Fabii 2012-04-02 18:35:17