[英]Unable to show ProgressDialog on mp3 media player while prepare
我有一个媒体播放器,播放器来自url的mp3。 我想在从网址加载音频时显示进度对话框。 这是我的代码..我是新的代码所以请不要介意,如果你不能理解我的问题。 提前致谢
发挥功能
public void playSong(int naatindex){
// Play song
tv = (TextView) this.findViewById(R.id.mywidget);
tv.setText("Buffering....");
tv.setSelected(true);
final ProgressDialog progressDialog = ProgressDialog.show(this,
"Loading Title", "Loading Message");
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (progressDialog != null && progressDialog.isShowing()){
progressDialog.dismiss();
}
mp.start();
}
});
try {
mp.reset();
mp.setDataSource(naatpaths[naatindex]);
tv = (TextView) this.findViewById(R.id.mywidget);
tv.setSelected(true);
mp.prepare();
// Set focus to the textview
tv.setText(naattitles[naatindex]);
// Changing Button Image to pause image
btnPlay.setImageResource(R.drawable.btn_pause);
// set Progress bar values
songProgressBar.setProgress(0);
songProgressBar.setMax(100);
// Updating progress bar
updateProgressBar();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
你必须使用prepareAsync(); 并创建另一个文本视图,文本正在缓冲。 而prepareAsync()可见缓冲textview。 并准备完整的lister hide缓冲textview。 我希望工作
public void playSong(final int naatindex){
// Play song
tv = (TextView) this.findViewById(R.id.mywidget);
bf = (TextView) this.findViewById(R.id.showbuffering);
try {
mp.reset();
mp.setDataSource(naatpaths[naatindex]);
tv.setVisibility(View.INVISIBLE);
bf.setVisibility(View.VISIBLE);
mp.prepareAsync();
mp.setOnPreparedListener(new OnPreparedListener(){
@Override
public void onPrepared(MediaPlayer mp){
bf.setVisibility(View.INVISIBLE);
tv.setVisibility(View.VISIBLE);
tv.setSelected(true);
mp.start();
tv.setText(naattitles[naatindex]);
tv.setSelected(true);
// Changing Button Image to pause image
btnPlay.setImageResource(R.drawable.btn_pause);
// set Progress bar values
songProgressBar.setProgress(o);
songProgressBar.setMax(100);
// Updating progress bar
updateProgressBar();
}
});
// Set focus to the textview
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.