I have an application with a video player. I implemented a method that stores the current position in the video so that the next time user plays the same video, it is played from where the user left it. However, I am unable to load the video from the position from where it is left. The log cat shows this error continuously
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x2b59c8 0(int# 0/0)
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x4a2ad0 0(int# 0/0)
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x2b5a20 0(int# 0/0)
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x1c09a0 0(int# 0/0)
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.699: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x3dafa0 0(int# 0/0)
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Unknown event: 1
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x2b59c8 0(int# 0/0)
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x1c4028 0(int# 0/0)
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x2b5a20 0(int# 0/0)
10-23 21:23:23.707: ERROR/TI_Video_Decoder(1250): Corrupted Data in buffer 0x4a2ad0 0(int# 0/0)
This is my code for playing the video. Can anyone guide me here why I am getting this error. Thanks.. Here is the code
public class Player extends Activity {
private static Context mContext;
private int mStartTime = 0;
private int sliderPosition;
private int setTime;
private String uriString;
private MediaPlayer player;
private class ErrorListener implements OnErrorListener {
private class CompletionListener implements OnCompletionListener {
// FIXME: @Override
public void onCompletion(MediaPlayer mp) {
mContext = null;
mStartTime = 0;
System.exit(-1);
}
}
private static Context getContext() {
return mContext;
}
private static void setContext(Context context) {
mContext = context;
}
@Override
public void onCreate(Bundle savedInstanceState) {
System.gc();
super.onCreate(savedInstanceState);
setContext(this);
Intent intent = getIntent();
Uri uri = intent.getData();
uriString = intent.getStringExtra("filename" );
if (uri != null) {
setContentView(R.layout.videoview);
VideoView videoView = (VideoView) findViewById(R.id.videoview);
videoView.setVideoURI(uri);
videoView.setMediaController(new MediaController(this));
videoView.setOnErrorListener(new ErrorListener());
videoView.setOnCompletionListener(new CompletionListener());
videoView.setKeepScreenOn(true);
videoView.requestFocus();
}
}//onCreate Method Ends
public void onStart(){
super.onStart();
VideoView videoView = (VideoView) findViewById(R.id.videoview);
SharedPreferences Settings = getSharedPreferences("MyStoragePreferences", MODE_PRIVATE);
if(Settings.contains(uriString))
{
setTime= Settings.getInt(uriString, 0);
videoView.seekTo(setTime);
videoView.start();
}
else
{
videoView.seekTo(mStartTime);
videoView.seekTo(0);
if (mStartTime == 0){
videoView.start();
}
}
}
public void onSaveInstanceState(Bundle outState){
VideoView videoView = (VideoView) findViewById(R.id.videoview);
mStartTime = videoView.getCurrentPosition();
outState.putInt("restartTime", mStartTime);
super.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
mContext = null;
super.onDestroy();
}
@Override
protected void onStop(){
super.onStop();
VideoView videoView = (VideoView) findViewById(R.id.videoview);
videoView.stopPlayback();
}
@Override
protected void onPause(){
super.onPause();
VideoView videoView = (VideoView) findViewById(R.id.videoview);
sliderPosition= videoView.getCurrentPosition();
SharedPreferences Settings = getSharedPreferences("MyStoragePreferences", MODE_PRIVATE);
SharedPreferences.Editor prefEditor = Settings.edit();
prefEditor.putInt(uriString, sliderPosition);
prefEditor.commit();
}
}
From the documentation:
The reason you are probably getting this error is because the media player seeks slowly, so by the time you start playing your video, it is not done seeking. Hence it reads corrupted buffers