How to capture a frame form MediaPlayer???

All your problems with Audio, Video and Images.

How to capture a frame form MediaPlayer???

Postby eidolon » Thu Dec 31, 2009 6:42 am

Hi all,I want to capture the screen as a image when MediaPlayer is playing.How can i do it???

Thx.....
eidolon
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Dec 31, 2009 6:18 am

Top

Postby wjspoel » Sat Jan 02, 2010 1:33 pm

I don't have an answer, but I am interested what the solution is (if there is one).

I looked into this a few weeks ago which didn't result in an awnser, but the following things are worth posting...
-The method in the mediaplayer class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public native Bitmap getFrameAt(int msec) throws IllegalStateException;
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

isn't callable.
-MediaMetadataRetriever.captureframe() looks like the solution, but does't exist (2.0) and in previous versions never seemed to work...
-searching for making a "screenshot" of the playing surfaceview also didn't solve anything

possibilities I haven't looked for yet is:
-getting access to the frame buffer
-using the NDK to create the functionality
-...


edit1:
Although it isn't an awnser to your question, maybe it is usable in someway: How to capture screen with coding


edit2:
According to API changes summary of android 2.0 it "looks like" that there is something which can do the trick:
Media
-MediaScanner now generates thumbnails for all images when they are inserted into MediaStore.
-New Thumbnail API for retrieving image and video thumbnails on demand.
... but maybe with a thumbnail the mean the first frame only ...
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Postby eidolon » Tue Jan 05, 2010 2:53 am

wjspoel wrote:I don't have an answer, but I am interested what the solution is (if there is one).

I looked into this a few weeks ago which didn't result in an awnser, but the following things are worth posting...
-The method in the mediaplayer class
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public native Bitmap getFrameAt(int msec) throws IllegalStateException;
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

isn't callable.
-MediaMetadataRetriever.captureframe() looks like the solution, but does't exist (2.0) and in previous versions never seemed to work...
-searching for making a "screenshot" of the playing surfaceview also didn't solve anything

possibilities I haven't looked for yet is:
-getting access to the frame buffer
-using the NDK to create the functionality
-...


edit1:
Although it isn't an awnser to your question, maybe it is usable in someway: How to capture screen with coding


edit2:
According to API changes summary of android 2.0 it "looks like" that there is something which can do the trick:
Media
-MediaScanner now generates thumbnails for all images when they are inserted into MediaStore.
-New Thumbnail API for retrieving image and video thumbnails on demand.
... but maybe with a thumbnail the mean the first frame only ...


Thanks very much,I'll try it.
eidolon
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Dec 31, 2009 6:18 am

Postby wjspoel » Tue Jan 05, 2010 10:44 am

Your welkom, and I am interested in an answer too :)

I tried to take a screenshots of a SurfaceView (with the code below) while playing a video, but this results in a black screen...

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                Bitmap screenshot;              
  3.  
  4.                         mPreview.setDrawingCacheEnabled(true);
  5.  
  6.                         //screenshot = Bitmap.createBitmap(mPreview.getDrawingCache());
  7.  
  8.                         screenshot = Bitmap.createBitmap(mPreview.getMeasuredWidth(),
  9.  
  10.                                         mPreview.getMeasuredHeight(), Bitmap.Config.RGB_565);
  11.  
  12.  
  13.  
  14.                                
  15.  
  16.                         mPreview.setDrawingCacheEnabled(false);
  17.  
  18.                        
  19.  
  20.                         String filename = String.valueOf(System.currentTimeMillis()) ;
  21.  
  22.                          
  23.  
  24.                         ContentValues values = new ContentValues();                    
  25.  
  26.                         values.put(Images.Media.TITLE, filename);
  27.  
  28.                         values.put(Images.Media.DATE_ADDED, System.currentTimeMillis());
  29.  
  30.                         values.put(Images.Media.MIME_TYPE, "image/jpeg");
  31.  
  32.                          
  33.  
  34.                         Uri uri = getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
  35.  
  36.                         try {
  37.  
  38.                                 OutputStream outStream = getContentResolver().openOutputStream(uri);
  39.  
  40.                                 screenshot.compress(Bitmap.CompressFormat.JPEG, 90, outStream);
  41.  
  42.                                 outStream.flush();
  43.  
  44.                                 outStream.close();
  45.  
  46.                                 Log.d("done","done");
  47.  
  48.                         } catch (FileNotFoundException e) {
  49.  
  50.                                 // TODO Auto-generated catch block
  51.  
  52.                                 e.printStackTrace();
  53.  
  54.                         } catch (IOException e) {
  55.  
  56.                                 // TODO Auto-generated catch block
  57.  
  58.                                 e.printStackTrace();
  59.  
  60.                         }
  61.  
  62.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Gonna test te code with others views to be sure it's not te screenshot code wich is te problem. Secondly, I haven't got enough knowledge about the surfaceview, it's holder, thread etc...So maybe I have to look more into that or maybe someone else can fill in the gaps
wjspoel
Junior Developer
Junior Developer
 
Posts: 18
Joined: Thu Dec 24, 2009 10:40 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 24 guests