2017-08-05 19 views
0

オーディオプレーヤーのアプリで作業していますが、新しいarraylistを送信するとクラッシュします。エラーの内容を理解できません。 これはエラーログです。新しい曲を再生するときにIllegalStateExceptionが発生する

java.lang.RuntimeException: Error receiving broadcast Intent { act=beatbox.neelay.dummybeat.PlayNewAudio flg=0x10 } in [email protected] 
                     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:893) 
                     at android.os.Handler.handleCallback(Handler.java:739) 
                     at android.os.Handler.dispatchMessage(Handler.java:95) 
                     at android.os.Looper.loop(Looper.java:148) 
                     at android.app.ActivityThread.main(ActivityThread.java:5441) 
                     at java.lang.reflect.Method.invoke(Native Method) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) 
                    Caused by: java.lang.IllegalStateException 
                     at android.media.MediaPlayer._setAudioStreamType(Native Method) 
                     at android.media.MediaPlayer.setAudioStreamType(MediaPlayer.java:1732) 
                     at unnion.neelay.beatbox.MediaService.initMediaPlayer(MediaService.java:408) 
                     at unnion.neelay.beatbox.MediaService.access$1500(MediaService.java:52) 
                     at unnion.neelay.beatbox.MediaService$6.onReceive(MediaService.java:904) 
                     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:883) 
                     at android.os.Handler.handleCallback(Handler.java:739)  
                     at android.os.Handler.dispatchMessage(Handler.java:95)  
                     at android.os.Looper.loop(Looper.java:148)  
                     at android.app.ActivityThread.main(ActivityThread.java:5441)  
                     at java.lang.reflect.Method.invoke(Native Method)  
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)  
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)  

解決方法を教えてもらえますか。 これは状態を再生するにsetAudioStreamTypeを呼び出すことは避けてください

private void initMediaPlayer() { 
    if (mediaPlayer == null) 
     mediaPlayer = new MediaPlayer();//new MediaPlayer instance 

    mediaPlayer.setOnCompletionListener(this); 
    mediaPlayer.setOnErrorListener(this); 
    mediaPlayer.setOnPreparedListener(this); 
    mediaPlayer.setOnBufferingUpdateListener(this); 
    mediaPlayer.setOnSeekCompleteListener(this); 
    mediaPlayer.setOnInfoListener(this); 
    //Reset so that the MediaPlayer is not pointing to another data source 



    StorageUtil active = new StorageUtil(getApplicationContext()); 
    active.storeActiveIndex(audioIndex); 


    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    try { 
     // Set the data source to the mediaFile location 
     mediaPlayer.reset(); 
     mediaPlayer.setDataSource(activeAudio.getFile_uri()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     stopSelf(); 
    } 


    mediaPlayer.prepareAsync(); 
    messagesent(); 
} 

答えて

0

を示す方法です。 MediaPlayerをリリースすることを忘れないでください。

private void initMediaPlayer() { 
    if (mediaPlayer == null) { 
     mediaPlayer = new MediaPlayer();//new MediaPlayer instance 

     mediaPlayer.setOnCompletionListener(this); 
     mediaPlayer.setOnErrorListener(this); 
     mediaPlayer.setOnPreparedListener(this); 
     mediaPlayer.setOnBufferingUpdateListener(this); 
     mediaPlayer.setOnSeekCompleteListener(this); 
     mediaPlayer.setOnInfoListener(this); 
     mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    } 

    //Reset so that the MediaPlayer is not pointing to another data source 

    StorageUtil active = new StorageUtil(getApplicationContext()); 
    active.storeActiveIndex(audioIndex); 

    try { 
     // Set the data source to the mediaFile location 
     mediaPlayer.reset(); 
     mediaPlayer.setDataSource(activeAudio.getFile_uri()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     stopSelf(); 
    } 

    mediaPlayer.prepareAsync(); 
    messagesent(); 
} 
関連する問題