0

我有一个全屏视频视图,并且想在按下某个键时触发一个 popupMenu。日志显示关键事件被捕获,但弹出视图不会显示。任何想法为什么?

 @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;

   }
  });

}

4

1 回答 1

0

看起来

KeyEvent.KEYCODE_DPAD_CENTER

是默认设置为由VideoView触发的事件。因此,当我按下该键时,VideoView 触发了它的事件事件,而不是我请求它的事件。我将 KeyEvent KEYCODE 更改为另一个键(Videoview 未使用的键)并且它有效。

于 2012-04-03T01:28:42.990 回答