Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have a problem with seekTo() method from MediaPlayer. It seems it doesn't work at all! I followed other threads regarding this issue and tried different workarounds but still seekTo() does nothing! Here is my code:
private MediaPlayer mMediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
final VideoView videoView = (VideoView)findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
final Uri video = Uri.parse("android.resource://"+getPackageName()+"/"+R.drawable.video_myopia);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer = mp;
System.out.println("CURRENT POSITION 0: " + mp.getCurrentPosition());
mp.seekTo(3000);
System.out.println("CURRENT POSITION 1: " + mp.getCurrentPosition());
mp.start();
System.out.println("CURRENT POSITION 2: " + mp.getCurrentPosition());
The System.out.println() shows the following output:
POSITION 0: 0
POSITION 1: 3000
POSITION 2: 3000
(note: I also tried to start() before seekTo() and then start() again after the seekTo() method)
so after the mp.start() line the mp.getCurrentPosition() says that it is at 3000 but the problem is that it's not! The video starts from the beginning. In each situation that I tried seek, after seekTo(ms) and start() the video starts from the beginning no matter what.
I must mention that I also used mp.setOnSeekCompleteListener() to know when the seek finishes. In this callback I tried to start() the video again, but it always starts from the beginning.
Can someone help me please? I will be grateful for any suggestion :). Thanx!
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.