2012-01-03 97 views
1

我要趕MediaPlayer的錯誤是這樣的:抓住Android的MediaPlayer的錯誤

01-03 21:03:08.797: E/MediaPlayer(9470): error (1, -2147483648) 

或本

01-03 20:52:48.859: E/MediaPlayer(8674): error (1, -1004) 

哪個異常,我需要趕上?我試過

try { 
     mp.start(); 
    } 

    catch (IllegalArgumentException e){Log.d(TAG, "error1");} 
    catch (IllegalStateException e) {Log.d(TAG, "error2");} 
    catch (Exception e){Log.d(TAG, "error2");} 

但它不起作用。任何人都可以告訴我,我必須捕捉哪個異常?

+0

你修復錯誤(1,-2147483648)?如果是的話,你可以與我分享解決方案嗎?我有同樣的錯誤。 – 2013-05-08 15:56:24

回答

8

你需要在你的Fragment或Activity中實現android.media.MediaPlayer.OnErrorListener。

/* 
    * Called to indicate an error. Parameters 
    * 
    * mp the MediaPlayer the error pertains to what the type of error that has 
    * occurred: MEDIA_ERROR_UNKNOWN MEDIA_ERROR_SERVER_DIED extra an extra 
    * code, specific to the error. Typically implementation dependant. Returns 
    * True if the method handled the error, false if it didn't. Returning 
    * false, or not having an OnErrorListener at all, will cause the 
    * OnCompletionListener to be called. 
    */ 
    @Override 
    public boolean onError(MediaPlayer mp, int what, int extras) { 

     return true; 
    } 

當您創建的MediaPlayer確保您撥打

mediaPlayer.setOnErrorListener(this); 
+0

非常非常非常非常非常感謝你 – Nabin 2016-03-05 06:07:26