• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Access Video Frames via MediaPlayer

paulscode

Member
Mar 18, 2010
86
14
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:
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setDataSource( pathToSomeVideoFile );
int width = mPlayer.getVideoWidth();
int height = mPlayer.getVideoHeight();
Bitmap bMap = Bitmap.createBitmap( width, height, Bitmap.Config.ARGB_4444 );
Canvas c = new Canvas( bMap );
SurfaceView sView = new SurfaceView( ????  );  // What goes here?
SurfaceHolder sHolder = sView.getHolder();
mPlayer.setDisplay( sHolder );
mPlayer.prepare();
mPlayer.start();

// Then, to grab the current video frame:
sView.draw( c );
// 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?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones