Access Video Frames via MediaPlayer

Last Updated:

  1. paulscode

    paulscode Well-Known Member This Topic's Starter

    Mar 18, 2010
    Likes Received:
    I am trying to devise a way to access a playing video's current frame into a Bitmap context, without actually displaying the video on the screen (i.e. it is "playing" in memory, but not visible). Digging through the documentation, it seems one way would be through a SurfaceHolder interface. Does anyone know how to create a SurfaceHolder implementation that is not attached to the actual display? I have worked out a basic design, which would go something like this:
    Code (Text):
    1. MediaPlayer mPlayer = new MediaPlayer();
    2. mPlayer.setDataSource( pathToSomeVideoFile );
    3. int width = mPlayer.getVideoWidth();
    4. int height = mPlayer.getVideoHeight();
    5. Bitmap bMap = Bitmap.createBitmap( width, height, Bitmap.Config.ARGB_4444 );
    6. Canvas c = new Canvas( bMap );
    7. SurfaceView sView = new SurfaceView( ????  );  // What goes here?
    8. SurfaceHolder sHolder = sView.getHolder();
    9. mPlayer.setDisplay( sHolder );
    10. mPlayer.prepare();
    11. mPlayer.start();
    13. // Then, to grab the current video frame:
    14. sView.draw( c );
    15. // bMap should now hold the current frame
    As you can see, the only problem with this method, is I must supply a "Context" to the SurfaceView constructor, such that it doesn't point to the actual screen. Any ideas what should go in there? Or am I way of track and there is an easier way to accomplish what I'm trying to do here?


Share This Page