Search code examples
androidvideomultimedia

Video plays just the first 5 seconds


Using:

private void play() {
    VideoView v = (VideoView) findViewById(R.id.videoView);
    MediaPlayer mp = MediaPlayer.create(this, R.raw.video);
    mp.setDisplay(v.getHolder());
    mp.start();
}

My video plays just about 5 first seconds, and stay like paused.. why does it happen? Is it something related to buffer? (I'm playing a local resource)

--

I've tried another 3gp video, and the same problem happens.


Solution

  • Working code (maybe was some problem with resource overuse):

    private void play() throws Exception {
        v = (VideoView) findViewById(R.id.videoView);
        if (!firstPlay) {
            mp.release();
        }
        mp = MediaPlayer.create(this, R.raw.video);
        mp.setDisplay(v.getHolder());
        mp.start();
        firstPlay = false;
    }