ProgressDialogが表示されません。私のプログラムでは、ユーザーがポップアップメニューからビットレートを選択すると、コンテンツがオンラインでフェッチされ、VideoViewに表示されます。
ただし、ビデオがロードされている間は黒い画面しか表示されず、ビデオが最終的にロードされる前に、progressDialogが最後に一瞬(またはそれ以下)表示されます。
private void showPopupMenu(View v){
popupMenu = new PopupMenu(VideoPlayer.this, v);
if(bitRates != null){
int menuItem = 0;
int index = bitRates.size()-1;
popupMenu.getMenu().add(0,menuItem, 0,"Hide menu");
for(int i=1;i<bitRates.size();i++){
menuItem = i;
popupMenu.getMenu().add(0,menuItem, 0,"Quality"+" : "+bitrateCheck(bitRates.get(index))).setCheckable(true);
Log.i("ITEM",qualityList.get(i)+" : "+bitRates.get(i));
index--;
}
popupMenu.getMenu().add(0,menuItem++, 0,"Catalog");
}
popupMenu.show();
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem item) {
p_dialog = ProgressDialog.show(VideoPlayer.this, "", "Loading...");
//get current position of video to seek to
final int position = mVideoView.getCurrentPosition();
new Thread() {
public void run() {
try{
runOnUiThread(new Runnable() {
public void run() {
if(item.getTitle().equals("Catalog")){
backButtonVideo(new View(VideoPlayer.this));
}
else if(item.getTitle().equals("Hide menu")){
popupMenu.dismiss();
mVideoView.start();
}
else{
play(streamUrls.get(item.getItemId()),position);
}
}
});
}
catch (Exception e) {
Log.e("tag", e.getMessage());
}
p_dialog.dismiss();
}
}.start();
return true;
}
});
}
public void play(String _videoUri, int position){
Log.i(TAG,"URI is : "+Uri.parse(_videoUri).toString());
//View view = new View()
MediaController mc = new MediaController(VideoPlayer.this);
mVideoView.setMediaController(mc);
mVideoView.setVideoURI(Uri.parse(_videoUri));
mVideoView.requestFocus();
mVideoView.seekTo(position);
mVideoView.start();
}
////////////////////////新しいコードで編集:提案に従って////////////////// ///ダイアログがまったく表示されなくなりました。
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
mVideoView.start();
}
});
////////////////////////////////////////////////// /////////////////////////////////
popupMenu.show();
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem item) {
//get current position of video to seek to
final int position = mVideoView.getCurrentPosition();
p_dialog = ProgressDialog.show(VideoPlayer.this, "", "Loading...");
try{
if(item.getTitle().equals("Catalog")){
backButtonVideo(new View(VideoPlayer.this));
}
else if(item.getTitle().equals("Hide menu")){
popupMenu.dismiss();
mVideoView.start();
}
else{
play(streamUrls.get(item.getItemId()),position);
}
}
catch (Exception e) {Log.e("tag", e.getMessage());}
return true;
}
});
}
public void play(String _videoUri, int position){
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.seekTo(position);
p_dialog.dismiss();
}