Search code examples
androidvideomedia-player

Media Player Show video


Why doesn't the MediaPlayer show the video as soon as it is available. What I mean is on the IPhone when a video is played the video shows up right away. Even when returning from pause. But on the Android the screen stays black for a couple of milliseconds to a second depending on the device used and how many processes are running in the background.

I'm asking this because i want to use one of the beginning frames from my video play as a type of screenshot and currently I'm using a handler to wait 1 second before pausing the video.

Can someone tell me a quick way to make the video show up as soon as it is started or even prepared instead of my workaround?

EDIT: Here is how I prepare my video player so It should be prepared right.

private void initVideo() 
{
    Log.i("VideoPlayer", "Initialize Video File" + videoFileName);

    AssetFileDescriptor afd;
    try {
        if(videoFileName != null);
        {

            afd = getAssets().openFd(videoFileName);

            vidplayer = new MediaPlayer();

            vidplayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());

            vidplayer.setDisplay(holder);
            vidplayer.prepare();
            vidplayer.setOnCompletionListener(this);
            vidplayer.setOnPreparedListener(this);  
            //Log.i("INITVIDEO", Integer.toString(videoPausedAt));
            vidplayer.seekTo(videoPausedAt);
            //Log.i("VideoPlayer", "video Prepared");

            videoDuration = vidplayer.getDuration()/1000;


            isVideoReady = true;

        }

    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e)
    {
        //Log.i("InitPlayer", e.getClass().toString());
        e.printStackTrace();
    }


}

Solution

  • I have found that it is the phones fault.(mostly) Video's will show up automatically unless phone is bogged down with apps and thus loading of the video takes longer (noticed after having a voip service running).