gpt4 book ai didi

java - 准备时无法在 mp3 媒体播放器上显示 ProgressDialog

转载 作者:太空狗 更新时间:2023-10-29 14:11:24 25 4
gpt4 key购买 nike

我有一个媒体播放器,可以从 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();
}
}

最佳答案

您必须使用 prepareAsync();并创建另一个正在缓冲文本的 TextView 。而 prepareAsync() 可见缓冲 TextView 。并在准备好的完整列表器上隐藏缓冲 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();
}
}

关于java - 准备时无法在 mp3 媒体播放器上显示 ProgressDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27756623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com