MediaPlayer在暂停mp3之后继续流式传输



我正在使用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) {
    }
}

而不是使用reset()方法使用pause()

mplayer.reset((;是重置您的媒体播放器,这意味着播放器重新启动。使用mplayer.stop((;为了停止媒体播放器或mplayer.pape((;暂停播放器

相关内容

  • 没有找到相关文章

最新更新