需要你的帮助,我在你按下按钮时检查音频流,或者当你按下一个按钮并且音频流不可用时启动程序然后没有发生,音乐不播放没有任何来自该计划的回复我不想让你意识到这样的回应怎么做呢?
启动代码媒体播放器:
public void playMain() {
releaseMP();
Log.d(LOG_TAG, "start Stream");
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
if(pdaStream.isChecked()){
Main_stream = "http://145.255.233.204:58000/radio_pda";
}else{
Main_stream = "http://145.255.233.204:58000/radio";
}
mediaPlayer.setDataSource(Main_stream);
} catch (IOException e) {
e.printStackTrace();
}
Log.d(LOG_TAG, "prepareAsync");
mediaPlayer.prepareAsync();;
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
答案 0 :(得分:1)
在MediaPlayer创建对象之前,只需启动进度对话框,然后在mediaPlayer.start()之后将其关闭。
试试这个并告诉我。
protected void onPreExecute() {
//start you progress dialog here
}
@Override
protected Void doInBackground(Void... arg0) {
try {
mMediaPlayer
.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(
getApplicationContext(),
mMediaPlayer.prepareAsync();
return null;
}
@Override
protected void onPostExecute(Void result) {
mMediaPlayer.start();
// dismiss your dialog here
}
}
};
task.execute();