Android development (e.g. duration or preview video) acquired video information

Foreword

  Android was acquired in the video information achieved mainly rely MediaMetadataRetriever

Get the best video preview

So-called best is MediaMetadataRetriever own calculations

    / ** 
     * Get video thumbnail 
     * @param vedioFile 
     * @return 
     * / 
    public  static Bitmap getVedioThumbnail (File vedioFile) {
         IF (! {VedioFile.exists ()) 
            Le ( "video file does not exist" );
             return  null ; 
        } 

        Retriever. MediaMetadataRetriever is = new new . MediaMetadataRetriever is (); 
        retriever.setDataSource (vedioFile.getAbsolutePath ()); 
        Bitmap Bitmap = retriever.getFrameAtTime ();
         return Bitmap; 

    }

If your video file is a file in assets

Adf = context.getAssets AssetFileDescriptor () openFd (vedioFile.getAbsolutePath ());. // If the file is a video app assets directory 
retriever.setDataSource (adf.getFileDescriptor ());

Obtaining video preview time position specified in FIG.

/ ** 
     * Get video thumbnail 
     * @param vedioFile 
     * @return 
     * / 
    public  static Bitmap getVedioThumbnail (File vedioFile) {
         IF (! {VedioFile.exists ()) 
            Le ( "video file does not exist" );
             return  null ; 
        } 

        Retriever. MediaMetadataRetriever is = new new . MediaMetadataRetriever is (); 
        retriever.setDataSource (vedioFile.getAbsolutePath ()); 
        Bitmap Bitmap = retriever.getFrameAtTime (1000); // parameter milliseconds, return frame is close to the time of FIG 
        return Bitmap;

    }

Length get video play

    / ** 
     * return the total length video playback 
     * @param vedioFile 
     * @return 
     * / 
    public  static Long getVedioTotalTime (File vedioFile) {
         IF (! VedioFile.exists ()) { 
            Le ( "video file does not exist" );
             return  null ; 
        } 
        . MediaMetadataRetriever is Retriever = new new . MediaMetadataRetriever is (); 
        retriever.setDataSource (vedioFile.getAbsolutePath ()); 
        String TimeString =   retriever.extractMetadata (MediaMetadataRetriever.METADATA_KEY_DURATION); 
        Long Time= Long.valueOf(timeString);
        return time;

    }

Additional information refer to Table

    / ** 
    * metadata key, numeric strings described for retrieving
     * sequential recording original audio data source.
    * /
     Public  static  Final  int METADATA_KEY_CD_TRACK_NUMBER = 0 ;
     / ** 
    metadata key is used to retrieve information about the album title, the data source. 
    * /
     Public  static  Final  int METADATA_KEY_ALBUM =. 1 ;
     / ** 
    metadata key, to retrieve information about the artist of the data source. 
    * /
     Public  static  Final  int METADATA_KEY_ARTIST = 2 ;
     / ** 
    metadata key, for retrieving data about the source of information. 
    * /
     Public  static  Final  int=. 3 METADATA_KEY_AUTHOR ;
     / ** 
    metadata key, to retrieve information about the composer data source. 
    * /
     Public  static  Final  int METADATA_KEY_COMPOSER =. 4 ;
     / ** 
    for retrieving metadata key create a data source or modify date. 
    * /
     Public  static  Final  int METADATA_KEY_DATE =. 5 ;
     / ** 
    metadata key, content type, or the type of resource for retrieving data. 
    * /
     Public  static  Final  int METADATA_KEY_GENRE =. 6 ;
     / ** 
    for retrieving the data source metadata key header. 
    * /
     Public  static  Final  int METADATA_KEY_TITLE. 7 =;
     / * 
    Metadata key, for retrieving the data source to create or modify the year. 
    * /
     Public  static  Final  int METADATA_KEY_YEAR =. 8 ;
     / ** 
    metadata key, play duration for retrieving data source. 
    * /
     Public  static  Final  int METADATA_KEY_DURATION =. 9 ;
     / ** 
    for retrieving the track number of the metadata key, such as audio, video, text, data source, such as mp4 file or 3gpp. 
    * /
     Public  static  Final  int METADATA_KEY_NUM_TRACKS = 10 ;
     / ** 
    for the metadata key (e.g. OF words) of data sources to retrieve information. 
    * /
     Public  static  Final  int METADATA_KEY_WRITER. 11 =;
     / ** 
    * retrieval mime type of the data source metadata keys. Some 
    examples of mime type comprising: "Video / MP4", "Audio / MP4", "Audio / AMR- WB", etc.
     * /
     public  static  Final  int METADATA_KEY_MIMETYPE = 12 is ;
     / ** 
    metadata key for retrieving information about performers information on 
    the artist associated with the data source. 
    * /
     Public  static  Final  int METADATA_KEY_ALBUMARTIST = 13 is ;
     / ** 
    metadata key, for retrieving the digital string descriptor which 
    part of the audio data from the source. 
    * /
     Public  static  Final  int METADATA_KEY_DISC_NUMBER = 14 ;
     / **
    For retrieving music album editing status of metadata keys. 
    * /
     Public  static  Final  int METADATA_KEY_COMPILATION = 15 ;
     / ** 
    * If this key is present, then the media containing the audio content.
    * /
     Public  static  Final  int METADATA_KEY_HAS_AUDIO = 16 ;
     / ** 
    If this key is present, then the media containing the video content. 
    * /
     Public  static  Final  int METADATA_KEY_HAS_VIDEO =. 17 ;
     / ** 
    If the media contains video, this key will retrieve its width. 
    * /
     Public  static  Final  int METADATA_KEY_VIDEO_WIDTH = 18 is ;
     / **
    If the media including video, this key will retrieve its height. 
    * /
     Public  static  Final  int METADATA_KEY_VIDEO_HEIGHT =. 19 ;
     / ** 
    * This key retrieves average bit rate (in bits / seconds) (if available).
    * /
     Public  static  Final  int METADATA_KEY_BITRATE = 20 is ;
     / ** 
    This key retrieved text track language code (if any). If a plurality of tracks present text, the return value will be shown as follows:
     * /
     public  static  Final  int METADATA_KEY_TIMED_TEXT_LANGUAGES = 21 is ;
     / ** 
    If this key is present, then the media is protected. 
    * /
     Public  static  Final  int METADATA_KEY_IS_DRM = 22 is;
     / * 
    This key retrieve location information (if any). 
    The position of the ISO shall assign a mp4 / 3gp box "@xyz" -6709 standard. Longitude - 90 degrees and latitude 
    , for example, 180 degrees would be retrieved as " -90.0000 + 180.0000 ."
    * /
     Public  static  Final  int METADATA_KEY_LOCATION = 23 is ;
     / ** 
    This is a key to retrieve video rotational angle of the unit (if available). 
    Video rotation angle may be 0 degrees, 90 degrees, 180 degrees or 270 degrees. 
    * /
     Public  static  Final  int METADATA_KEY_VIDEO_ROTATION = 24 ;
     / ** 
    * This key to retrieve the original capture frame rate (if it is) available. Capture frame rate will be a floating-point number.
    * /
     Public  static  Final  int= 25 METADATA_KEY_CAPTURE_FRAMERATE ;
     / ** 
    If the key exists, the media content comprising still image. 
    * /
     Public  static  Final  int METADATA_KEY_HAS_IMAGE = 26 is ;
     / ** 
    * If the media contains a still image, this key will retrieve the number of still images.
    * /
     Public  static  Final  int METADATA_KEY_IMAGE_COUNT = 27 ;
     / ** 
    * If the media contains a still image, the key index to retrieve the main picture.
    * /
     Public  static  Final  int METADATA_KEY_IMAGE_PRIMARY = 28 ;
     / ** 
    * If the media contains a still image, retrieves the key width of the main image.
    * /
    public  static  Final  int METADATA_KEY_IMAGE_WIDTH = 29 ;
     / ** 
    * If the media contains a still image, this image height of the main key retrieved.
    * /
     Public  static  Final  int METADATA_KEY_IMAGE_HEIGHT = 30 ;
     / ** 
    * If the media contains still images, the angle of rotation of the key to retrieve the main picture (clockwise). The image must be one of the rotational angle 0 degrees, 90 degrees, 180 degrees or 270 degrees.
    * /
     Public  static  Final  int METADATA_KEY_IMAGE_ROTATION = 31 is ;
     / ** 
    * If the media contains video and this key is present, total number of frames in a video sequence is retrieved.
    * /
     Public  static  Final  int METADATA_KEY_VIDEO_FRAME_COUNT = 32;

 

Guess you like

Origin www.cnblogs.com/guanxinjing/p/11057994.html