[英]android media player mp3 streaming audio on the other wheel
have the following code to run an mp3 podcast 具有以下代码来运行mp3播客
public void playPodcast( final Uri data){
new Thread (new Runnable(){
public void run() {
if(!mediaPlayer.isPlaying()){
try {
mediaPlayer.setDataSource(getApplicationContext(), data);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaFileLengthInMilliseconds = mediaPlayer.getDuration();
duracaoPodcast = mediaPlayer.getDuration();
mediaPlayer.start();
if(!(controlTimer >= 1)){
timer();
controlTimer++;
}
primarySeekBarProgressUpdater();
}
}
}).start();
}
and to close the User Intent have: 并关闭用户意图有:
voltar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
mediaPlayer.stop();
}
});
the problem occurs when the User closes the intent that all the return button phones with android is because it does not: 当用户关闭所有带有android的回车电话的意图时,会发生问题,原因是它没有:
finish();
mediaPlayer.stop();
makes only: 只做:
finish();
and so the audio is still playing, even if I go back to that intent the pause: 因此即使我回到原意暂停,声音仍在播放:
stop.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mediaPlayer.isPlaying()){
mediaPlayer.stop();
frame.setVisibility(View.INVISIBLE);
}
}
});
button does not work, and if I press the play he starts a new audio on top of that emptied playing, 按钮不起作用,并且如果我按该播放,他会在该空播放的顶部开始播放新的音频,
any idea how to solve? 任何想法如何解决?
put mediaPlayer.stop();
把
mediaPlayer.stop();
in activity onStop()
Method as far as i understood your question. 据我了解您的问题,在活动
onStop()
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.