views:

52

answers:

2

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.

A: 

Combining a VideoView and a MediaPlayer may not be the right approach. VideoView uses its own MediaPlayer. Either use VideoView by itself, or use a combination of MediaPlayer and SurfaceView.

CommonsWare
Also, video playback on an emulator does not tend to work well, unless you have a very fast PC.
CommonsWare
Actually I have a very fast quad core here. By the way, how do I play the video using the MediaControler of your example?
Tom Brito
@Tom Brito: To play the `VideoView` sample, tap on the top portion of the screen to bring up the `MediaController`, or add a call to `play()` towards the end of the setup process. To play the `MediaPlayer` example, you should get a URL field when you start up the app, to type in the path to a streaming video clip to test.
CommonsWare
@CommonsWare but the MediaController don't have a play() method..
Tom Brito
@Tom Brito: `play()` is on `VideoView`.
CommonsWare
@CommonsWare: Are you sure? I'm not seeing it on the doc <http://developer.android.com/reference/android/widget/VideoView.html>
Tom Brito
@Tom Brito: Sorry, on `VideoView` it is `start()`. I wish they would keep a consistent naming convention...
CommonsWare
if I change my given answer from mp.start() to v.start() and mp.release() to v.stopPlayback() it does not work. By the way, the android developers page teach us to use the MediaPlayer in the way I did, not the VideoView directly. I wonder why, if the VideoView already have a MediaPlayer..
Tom Brito
A: 

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;
}
Tom Brito
trying back the first code, it takes o little longer to stop, I really think is because of resource overuse on my many plays..
Tom Brito