当前位置: 代码迷 >> Android >> prepareAsync called in state 一
  详细解决方案

prepareAsync called in state 一

热度:105   发布时间:2016-05-01 20:51:40.0
prepareAsync called in state 1
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
  相关解决方案