这是我的主要活动中的代码:
private void initControls()
{
streamButton = (Button) findViewById(R.id.button_stream);
streamButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
loading = (ProgressBar) findViewById(R.id.progressBar1);
Toast
.makeText(
MyActivity.this,
"The following stream is about to start" + station,
Toast.LENGTH_LONG).show();
player.playAudioFile(urlstring2);
streamButton.setEnabled(false);
notificate();
}
});
}
这是我启动媒体播放器本身的代码:
public class player extends MyMainActivity{
static MediaPlayer player;
private static final String TAG = player.class.getSimpleName();
public static void playAudioFile(String urlstring2) {
player = new MediaPlayer();
try {
player.setDataSource(urlstring2);
loading.setVisibility(View.VISIBLE);
player.prepareAsync();
//player.start();
} catch (Throwable thr) {
Log.e(TAG, "could not play audio", thr);
loading.setVisibility(View.INVISIBLE);
}
player.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
player.start();
loading.setVisibility(View.INVISIBLE);
}
});
}
public static void releasePlayer() {
if (player != null) {
// Player-Ressourcen freigeben
player.release();
player = null;
}
}
}
我想要做的是在用户按下“播放”按钮时显示progressBar(cicling),并且当媒体播放器开始播放时我需要它消失。atm 我只是在玩家开始玩并且永远不会消失后显示圆圈...
编辑:我让它工作。我确实像这样启动播放器: player.prepare(); 代替 player.prepareAsync(); 所以进度条显示了一个视图毫秒。