我找到了我自己的答案。我不知道這是否是一個好方法,但是:
if(videoFile != null)
{
Log.i("INITPLAYER", videoFile);
afd = getAssets().openFd(videoFile);
instructionVideoPlayer = new MediaPlayer();
instructionVideoPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
instructionVideoPlayer.setDisplay(holder);
instructionVideoPlayer.prepare();
instructionVideoPlayer.setOnCompletionListener(instructionVideoComplete);
instructionVideoPlayer.setOnPreparedListener(this);
}
else
Log.i("VideoPlayer", "noVideoFile");
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
Log.i(this.toString(), "IOEXception");
e.printStackTrace();
//Here is the fix:
instructionVideoPlayer.release();
instructionVideoPlayer = null;
initPlayer();
// reinit after prepare failed. although this can bring in an infinte loop if video file does not exits
} catch (Exception e)
{
Log.i("InitPlayer", e.getClass().toString());
e.printStackTrace();
}
這真的對我也有幫助。只是叫釋放。 ! – png