Mediaplayer可以单曲播放但不能循环播放,求解

MediaPlayer实现背景音乐播放时,播放一次时没错,循环播放时出错,望大神帮忙解决
public class FirstActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent=new Intent(FirstActivity.this,MusicSever.class);
startService(intent);
}

@Override
protected  void onDestroy(){
    Toast.makeText(FirstActivity.this,"活动完", Toast.LENGTH_LONG).show();
    Intent intent=new Intent(FirstActivity.this,MusicSever.class);
    stopService(intent);
    super.onDestroy();
}

}

然后这是server类
public class MusicSever extends Service{
public MediaPlayer me;

@Override
public void onCreate(){
    me=MediaPlayer.create(this,R.raw.yinyue1);//实例化播放器类
    super.onCreate();
    me.setLooping(true);
}

@Override
public int onStartCommand(Intent intent,int flag,int startId){
    me.start();
    me.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText(MusicSever.this,"在播放", Toast.LENGTH_LONG).show();
            me.start();
        }
    });
    me.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Toast.makeText(MusicSever.this,"出错", Toast.LENGTH_LONG).show();
            me.release();
            return false;
        }
    });
    return START_STICKY;
    // 在运行onStartCommand后service进程被kill后,并且没有新的intent传递给它
}

@Override
public void onDestroy(){
    Toast.makeText(MusicSever.this,"播放完", Toast.LENGTH_LONG).show();
    me.stop();
    me.release();
    super.onDestroy();

}

@Override
public IBinder onBind(Intent intent) {
    return null;
}

}

1个回答

换了一个音频文件后可以循环播放了。这又是什么情况,难道还有音频不支持循环播放????

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问