2012-01-03 53 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