2

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();
}

}

Eddy Freddy
  • 1,820
  • 1
  • 13
  • 18
Farhan
  • 3,206
  • 14
  • 49
  • 62

1 Answers1

2

From the documentation:

Although the asynchronuous seekTo(int) call returns right way, the actual seek operation may take a while to finish, especially for audio/video being streamed. When the actual seek operation completes, the internal player engine calls a user supplied OnSeekComplete.onSeekComplete() if an OnSeekCompleteListener has been registered beforehand via setOnSeekCompleteListener(OnSeekCompleteListener).

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

Reno
  • 33,594
  • 11
  • 89
  • 102
  • actually Sir, I waited for several minutes but it didn't work and the logcat at the same time was continuously generating errors that I showed in my question.. – Farhan Oct 24 '11 at 06:07
  • *You* should not wait, you should use the `OnSeekCompleteListener` to do the waiting. Call `videoView.start()` in the `OnSeekCompleteListener` – Reno Oct 24 '11 at 06:18
  • Sir, thanks for your answer. Can you please comment on why I am getting "corrupted data in buffer" error?? thanks alot – Farhan Oct 24 '11 at 06:53
  • One final advice Sir. Shall I use videoview or shall I use mediaplayer? Kindly please keep checking the comments at this page. Your help might solve my problem. Many Thanks – Farhan Oct 24 '11 at 07:49
  • Have [a look at this](http://stackoverflow.com/questions/4063071/setonseekcompletelistener-for-videoview-how-can-be-achieved). I think it is very doable. – Reno Oct 24 '11 at 07:52
  • Sir. I need to ask one important question. I am unable to use onSeekCompleteListener with videoview. Can you please advise me here.. – Farhan Oct 26 '11 at 04:35
  • 1
    Don't call me "Sir", I've not been knighted. yet. To answer your question I suggest you use [vitamio](http://vov.io/vitamio/)'s media framework, they have [implemented the VideoView with onSeekCompleteListener](http://vov.io/vitamio/api/io/vov/vitamio/widget/VideoView.html#setOnSeekCompleteListener(io.vov.vitamio.MediaPlayer.OnSeekCompleteListener)). It is free. – Reno Oct 26 '11 at 05:12
  • Thanks Reno. I'll surely look into this and will get back to you.. Thank you so much for your response. – Farhan Oct 31 '11 at 08:42
  • As an alternative to vitamio, you can try customizing VideoView yourself, please see this answer to [7990784](http://stackoverflow.com/questions/7990784/videoview-not-playing-video-from-desired-position/11938019#11938019). – Peter Tran Aug 13 '12 at 17:01
  • @Reno required your help in implementing seekTo(), right now its getting a time to play video back from the same position where it was left. Vitamio is not available. Can this solution be helpful? http://stackoverflow.com/a/9103715/379693 – Paresh Mayani Apr 05 '13 at 06:02
  • I don't think so @Paresh, but [this might work](http://stackoverflow.com/a/11938019/68805) because of cloning and modifying `VideoView` to work for you. – Reno Apr 09 '13 at 14:01