I have a VideoView which I want to use to play a movieclip. I use it like this to play it and it works.
VideoView vv = new VideoView(this);
vv.setVideoURI(Ur
Another solution that might work for people who are searching for this question:
In my case, the video was a resource in the app (that is, I knew everything about it and it wasn't going to change) and its last 500 ms were the same frame, so I ended up doing the following:
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.splash));
mVideoView.start();
findViewById(android.R.id.content).postDelayed(new WaitForSplashScreenToFinish(), mVideoView.getDuration() - 1000);
and the referenced class is:
private class WaitForSplashScreenToFinish implements Runnable {
@Override
public void run() {
if (mVideoView.isPlaying() && mVideoView.getCurrentPosition() >= mVideoView.getDuration() - 500) {
mVideoView.pause();
// Now do something else, like changing activity
} else {
findViewById(android.R.id.content).postDelayed(this, 100);
}
}
}
Explanation: Immediately after starting the video I create a Runnable and postDelayed it to the root view (android.R.id.content
) to the duration of the video, minus the length at which I'm willing to pause the video (and a generous buffer, because postDelayed isn't guaranteed to play exactly after the requested time)
Then, the runnable checks if the video arrived at its pause-time, if so it pauses it and does whatever else we want it to do. If it doesn't, it runs postDelayed again with itself, for a shortened time (100 ms in my case, but could be shorter)
Granted, this is far from being an ideal solution, but it might help someone with a specific problem similar to the one that stumbled me for half a day :)