Brilliafy / metadataretrieverwrapper

A AI2 Extension to wrap the Metadata Retriever class.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Metadata Retriever Wrapper

An AI2 Extension to wrap the MetadataRetriever class.

Reference: https://developer.android.com/reference/android/media/MediaMetadataRetriever

Why was it made

During the development of my 'roll dice!' app, I encountered a shocking issue... I couldn't animate the dice to roll precisely the duration of the sound effect, and I was not aware of any other extension available in the community to accomplish that same functionality I was looking for. SO I MADE MY OWN!

You could unmistakenly suggest that I could just have— hard-coded the duration of the specific audio file, to the timer of the animation. ..BUT WHERE'S THE FUN IN THAT?!?

Documentation

This extension currently wraps essentially all functions of the MetadataRetriever class, including:

  1. MetadataRetriever.ExtractMetadata(String absoluteFilename, int keyCode)
  2. MetadataRetriever.GetEmbeddedPicture(String absoluteFilename)
  3. MetadataRetriever.GetFrameAtIndex(String absoluteFilename, int frameIndex)
  4. MetadataRetriever.GetFrameAtTime(String absoluteFilename, long timeUs)
  5. MetadataRetriever.GetFrameAtTimeOptionOverload(String absoluteFilename, long timeUs, int option)
  6. MetadataRetriever.GetImageAtIndex(String absoluteFilename, int imageIndex)
  7. MetadataRetriever.GetPrimaryImage(String absoluteFilename)
  8. MetadataRetriever.GetScaledFrameAtTime(String absoluteFilename, long timeUs, int option, int dstWidth, int dstHeight)

Method return

All functions return type String. They return the absolute file path of the new extracted image in cache, aside from the function MetadataRetriever.ExtractMetadata, which returns metadata. Take for instance:

  • MetadataRetriever.ExtractMetadata(METADATA_KEY_DURATION) or preferably MetadataRetriever.ExtractMetadata(9), returns the duration in milliseconds, such as 3125
  • MetadataRetriever.ExtractMetadata(METADATA_KEY_TITLE) or preferably MetadataRetriever.ExtractMetadata(7), returns the title of media, if available, such as "My title"

Min API - Errors

Each function prerequisites a unique API level. Seeing that these functions are virtual methods, granted that one of them was invoked on a device with an older platform version than mandatory, instead of returning results, the method returns an error message. The current error message is: "ERROR! Insufficient API level."

On the occasion that the function fails, it generally returns an error message with a clause. You can handle them by checking if the string returned contains "ERROR!", as it is widely used as a universal error message prefix all across the extension. Setting a picture component as the error message, causes a crash! Ensure you scan the returned string to handle the error in your code, rather than rawly assigning the path of the image to a MetadataRetriever function.

Method Arguments - IO

The first argument, is usually the argument absoluteFilename, which is much self-explanatory. Unlike AI2, file:/// is a redundant prefix; the extension's functions execute without interference regardless of the occurrence of the prefix. Be that as it may, all paths returned from the functions, emphatically have to use and are returned with the file:/// prefix.

Furthermore, asset utilisation as a filepath is approved, despite if the application is running in development mode, thanks to the automatic debugging detection, which is an abstract of the AssetExtractor project, which you can visit here.

The file assigned can differ in file formats, since it is wrapping an Android pre-defined method, in accordance to your Android API level, explained thoroughly here for audio, and here for video.

All methods require an absolute file path of the target media, as of the MetadataRetriever.SetDataSource function, for it is necessary for relatively every method within the MetadataRetriever class.

Any other arguments required, are referenced in great detail inside the MediaMetadataRetriever Class Developer Reference.

Downloads

Click here to download the extension/project.

Closure

For any inquiries, contact me.

Thank you!

About

A AI2 Extension to wrap the Metadata Retriever class.

License:MIT License


Languages

Language:Java 90.3%Language:Shell 9.7%