我正在使用MediaPlayer进行流式传输问题是当用户回到开关盒时它没有恢复它每次用户切换时都会从头开始播放,谢谢我真的需要你的帮助:)
@Override
public void onCheckedChanged(RadioGroup rg, int i) {
int rIds = rGroup.getCheckedRadioButtonId();
switch (rIds){
case R.id.btn:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn1:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn2:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn3:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn4:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn5:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn6:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn7:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn8:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn9:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
case R.id.btn10:
if(mPlayer.isPlaying()) {
loadProgress();
mPlayer.reset();
streamMp3(CLASS.staticMethodforURL);
}else{
loadProgress();
streamMp3(CLASS.staticMethodforURL);
}
break;
}
}
private void streamMp3(String u) {
try {
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(u);
mPlayer.setLooping(true);
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(this);
} catch (Exception e) {
}
}
答案 0 :(得分:0)
而不是使用reset()
方法使用pause()
答案 1 :(得分:0)
mPlayer.reset();重置您的媒体播放器,这意味着播放器再次启动。使用mPlayer.stop();用于停止媒体播放器或mPlayer.pause();暂停播放器