Get the frame of the video

Source: Internet
Author: User

1 Local Files

mediametadataretriever---android API 10 is not open before-can reflect

Http://developer.android.com/reference/android/media/MediaMetadataRetriever.html

Private void initview ()  {    imgPic =  (ImageView)   Findviewbyid (r.id.img_pic);    seekbar =  (Seekbar)  findviewbyid ( R.id.seekbar);     mmr = new mediametadataretriever ();     mmr.setdatasource ("/sdcard/3.mp4");    //  gets the length of the video (in milliseconds)      string time = mmr.extractmetadata (mediametadataretriever.metadata_key_duration);     seekbar.setmax (Integer.parseint (time)  * 1000);     bt =   (Button)  findviewbyid (R.ID.BT);     bt.setonclicklistener (new  Onclicklistener ()  {         @Override          public void onclick (VIEW V)  {     Toast.maketext (mainactivity.this,  " "  + seekbar.getprogreSS (),  1). Show ();     bitmap bitmap = mmr.getframeattime ( Seekbar.getprogress (), Mediametadataretriever.option_closest_sync);    // bitmap  Bitmap = mmr.getframeattime (Seekbar.getprogress ());     imgpic.setimagebitmap ( Bitmap); System.out.println (Mmr.extractmetadata (mediametadataretriever.metadata_key_date) +  ""); System.out.println (Mmr.extractmetadata (mediametadataretriever.metadata_key_mimetype) +  "");//mmr.release () ;}     });}


Another thing to say

Thumbnailutils.createvideothumbnail (filePath, kind); Get thumbnails of videos-you can also get pictures

The source code is as follows--actually use or mediametadataretriever

    public static bitmap createvideothumbnail (String filePath,  Int kind)  {        Bitmap bitmap = null;         MediaMetadataRetriever retriever = new  Mediametadataretriever ();        try {             retriever.setdatasource (FilePath);             bitmap = retriever.getframeattime ( -1);         } catch  (Illegalargumentexception ex)  {             // Assume this is a  corrupt video file        } catch  ( RUNTIMEEXCEPTION EX)  {   &Nbsp;        // assume this is a corrupt  video file.        } finally {             try {                 retriever.release ();             } catch  (Runtimeexception ex)  {                 // Ignore failures  while cleaning up.            }         }        if  (bitmap  == null)  return null;        if  (kind = = images.thumbnails.mini_kIND)  {            // scale down  the bitmap if it ' s too large.             int width = bitmap.getwidth ();             int height = bitmap.getheight ();             int max = math.max (width, height);             if  (max > 512)  {                 float  scale = 512f / max;                 int w = math.round (scale * width);                 int h = math.round (scale * height);                 bitmap =  Bitmap.createscaledbitmap (bitmap, w, h, true);             }        } else if  (kind = = images.thumbnails.micro_kind)  {             bitmap = extractthumbnail (bitmap,                     TARGET_SIZE_MICRO_THUMBNAIL,                     target_ size_micro_thumbnail,                    &nBsp;options_recycle_input);        }         return bitmap;    }


2 Network Video streaming

Two methods are accepted in Http://www.tuicool.com/articles/uqmUFfY

Method One

Mediametadataretriever.setdatasource (String Uri, map<string, string> headers)

---algorithm exception---the problem is closer--

Method two---not validated--pending verification

Another extended version of FFmpeg Mediametadataretriever was found on GitHub, providing a unified interface to get video details and thumbnails, support for API 7+, (Android Comes with Mediametadataretriever only support API + +), while supporting URI

, supported file types for files, HTTP, HTTPS, MMS and MMSH supported encoding formats (audio & VIDEO): AAC, acc+, AVI, FLAC, MP2, MP3, MP4, OGG, 3GP and more! Extended Support: ICY Metadata (SHOUTcast Metadata) The use of the method is very simple, simply download the following package to the local decompression and then copy the Libs files into their own project Libs directory can be https://github.com/ Wseemann/ffmpegmediametadataretriever/blob/master/fmmr-library/prebuilt-libs.tar.gz.


Vitemio Online test Flow http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8


Get the frame of the video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.