为什么我的函数不被调用?

时间:2012-04-01 20:16:49

标签: android progressdialog

我正在尝试在加载视频时显示ProgressDialog。 我的play(String _videoUri)函数似乎没有被调用。 谁能告诉我为什么?

我有一个完全相同的设置来启动一个新的Intent,它似乎工作正常,但不是在这种情况下或从给定的URL加载视频。

 private void showPopupMenu(View v){
   PopupMenu 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,"BitRate: "+bitRates.get(i));

          }
      }
  popupMenu.show(); 
  popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

   public boolean onMenuItemClick(final MenuItem item) {
       progressDialog = ProgressDialog.show(VideoPlayer.this, "", "Loading video...");
       new Thread() {

            public void run() {

                try{
                    play(streamUrls.get(item.getItemId())); 

                }
                catch (Exception e) 
                {

                    Log.e("tag", e.getMessage());

                }
                progressDialog.dismiss();
            }

        }.start();

       return true;

   }
  });


 }


  public void play(String _videoUri){
         Log.i(TAG,"URI is : "+Uri.parse(_videoUri).toString());
         MediaController mc = new MediaController(VideoPlayer.this);
         mVideoView.setMediaController(mc); 
         mVideoView.setVideoURI(Uri.parse(_videoUri));
         mVideoView.requestFocus();
         mVideoView.start();
  }

1 个答案:

答案 0 :(得分:0)

尝试将您的匿名线程放在括号中。     (new Thread(){...})。start()