Coder Social home page Coder Social logo

brilliafy / metadataretrieverwrapper Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 38.21 MB

A AI2 Extension to wrap the Metadata Retriever class.

License: MIT License

Java 90.34% Shell 9.66%
mit-app-inventor audio-library extension ai2 mit-appinventor2 mit-appinventor

metadataretrieverwrapper's Introduction

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!

metadataretrieverwrapper's People

Contributors

brilliafy avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.