我是一名有帮助的助手,以下是您需要翻译的内容:
我有一个媒体播放器,可以从URL播放mp3。我想在音频从URL加载时显示进度对话框。这是我的代码...我是新手,如果您无法很好地理解我的问题,请不要介意。提前致谢
播放功能
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();
}
}