0

我在我的应用程序中使用下面的代码来播放声音。但我不能玩它。有什么问题 ??

代码:

public void playSound(int resources){
    try{
        boolean mStartPlaying = true;
        MediaPlayer  mPlayer=null;
        if (mStartPlaying==true){
            mPlayer = new MediaPlayer();

            Uri uri = Uri.parse("android.resource://MY_PACKAGE/" + resources);
            mPlayer.setDataSource(getApplicationContext(),uri);
            mPlayer.prepare();
            mPlayer.start();
        } 
        else{
            mPlayer.release();
            mPlayer = null;
        }
        mStartPlaying = !mStartPlaying;
    }
    catch (IOException e){
        Log.e(LOG_TAG, "prepare() failed");
    }


}

我得到如下日志猫:

05-09 05:24:22.272: VERBOSE/PlayerDriver(95): Completed command PLAYER_INIT status=PVMFFailure
05-09 05:24:22.272: ERROR/PlayerDriver(95): Command PLAYER_INIT completed with an error or info PVMFFailure
05-09 05:24:22.272: ERROR/MediaPlayer(8072): error (1, -1)
05-09 05:24:22.272: ERROR/AudioPlayTest(8072): prepare() failed
05-09 05:24:22.282: VERBOSE/PVPlayer(95): run_set_video_surface s=-2147483648, cancelled=0
05-09 05:24:22.282: VERBOSE/PlayerDriver(95): HandleInformationalEvent: PVMFInfoErrorHandlingComplete
05-09 05:24:22.282: WARN/PlayerDriver(95): PVMFInfoErrorHandlingComplete
4

1 回答 1

1

也许您正在尝试播放不受支持的格式。你知道什么失败了吗?: new, setDataSource, prepare, start ... 而且 IOException 告诉你输入文件有问题,例如 FileNotFoundException 或 EOFException (尝试打印出更具体的异常,如建议here

ps.:在回答中移动评论。

于 2012-05-08T06:22:20.343 回答