- Java code
protected void onCreate(android.os.Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 首先加大音量 AudioManager audiomanager = (AudioManager) getSystemService(Service.AUDIO_SERVICE); audiomanager.setMode(AudioManager.MODE_NORMAL); audiomanager.setStreamVolume(AudioManager.STREAM_MUSIC, audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); audiomanager.adjustVolume(AudioManager.ADJUST_RAISE, 0); // 播放raw里面的mp3文件 MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.a); try { mediaPlayer.prepare(); mediaPlayer.setLooping(true); mediaPlayer.start(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } };
------解决方案--------------------
MediaPlayer.create()调用成功之后,MediaPlayer已经处于Prepared状态了,不可再prepare()/prepareAsync()
多看看API Reference Manual