npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nativescript-media-metadata-retriever

v1.0.77

Published

Plugin to retrieve the metadata of media files. Based on android's MediaMetadataRetriever class

Readme

Media Metadata Retriever Plugin for Nativescript

This plugin is based on the MediaMetadataRetriever in Android.

Installation

tns plugin add nativescript-media-metadata-retriever

Usage

This plugin is used to extract media metadata like albumname, artist, title, etc. from media files. This plugin can only be used in Android.

Example (Angular)

Typescript file (app.component.ts)

import { Component, OnInit } from "@angular/core";
import { MediaMetadataRetriever } from "nativescript-media-metadata-retriever";
import { Page } from "ui/page";
import { ImageFormat } from "ui/enums";

import * as imageSource from "image-source";
import * as fs from "file-system";
import * as permissions from "nativescript-permissions";  //Recommended
declare var android;

@Component({
    selector: "ns-app",
    templateUrl: "app.component.html",
    styleUrls: ["app.component.css"]
})

export class AppComponent { 
    path: string;
    artist: string;
    title: string;
    mmr: MediaMetadataRetriever;
    bitArray: Array<number>;
    allMetadata: string;
    src: string;

    constructor(private page: Page) { }

    ngOnInit(): void {
        this.mmr = new MediaMetadataRetriever();    //Create the object of the classs
    }

    //Get the metadata when the button is pressed
    getMetadata() {
        //Set the data source for the media file
        this.mmr.setDataSource(this.path + '');

        //Get a particular metadata
        this.mmr.extractMetadata(MediaMetadataRetriever._METADATA_KEY_TITLE)    //For title of media
        .then((args) => {
            this.title = args;
        });
        this.mmr.extractMetadata(MediaMetadataRetriever._METADATA_KEY_ARTIST)   //For artist name
        .then((args) => {
            this.artist = args;
        });

        //Get all the metadata
        this.mmr.extractAllMetadata()
        .then((args) => {
            this.allMetadata = JSON.stringify(args);
            /*
            You can also use args.title, args.artist, args.album ...
            as it includes a JSON array of objects
           */
        });

        //Get the Embedded Picture(Bitmap)
        this.mmr.getEmbeddedPicture()
        .then((args) => {
            var albumArt = this.page.getViewById("albumArt"); //Where albumArt is the ID of an Image element
            var img = new imageSource.ImageSource();
            img.setNativeSource(args);
            albumArt.set("src", img);
            console.log("ImageSource set...");
        })
        .catch((ex) => {
            //Do something else
            console.log("Failed to set ImageSource..." + ex);
        });
    }

    //This app needs storage permission
    //P.S. this is not necessary as you can do it manually by going into App Settings
    getPermissions(): void {
        if (!permissions.hasPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
            console.log("Asking for permissions...");
            permissions.requestPermissions([
                android.Manifest.permission.READ_EXTERNAL_STORAGE,
                android.Manifest.permission.WRITE_EXTERNAL_STORAGE
            ])
            .then(() => {
                console.log("Permissions granted...");
            })
            .catch(() => {
                console.log("Permissions denied...");
            })
        } else {
            console.log("App has necessary permissions...");
        }
    }
}

API

Set the data source for media file

  • setDataSource(path: string): Promise

Extract a single metadata based on given keycode

  • extractMetadata(keyCode: number): Promise

Extract all the metadata from the media file

  • extractAllMetadata(): Promise

Get the embedded picture from the file (Bitmap)

  • getEmbeddedPicture(): Promise<android.graphics.Bitmap>

KEYCODES

  • _METADATA_KEY_ALBUM
  • _METADATA_KEY_ALBUMARTIST
  • _METADATA_KEY_ARTIST
  • _METADATA_KEY_AUTHOR
  • _METADATA_KEY_BITRATE
  • _METADATA_KEY_CD_TRACK_NUMBER
  • _METADATA_KEY_COMPILATION
  • _METADATA_KEY_COMPOSER
  • _METADATA_KEY_DATE
  • _METADATA_KEY_DISK_NUMBER
  • _METADATA_KEY_DURATION
  • _METADATA_KEY_GENRE
  • _METADATA_KEY_HAS_AUDIO
  • _METADATA_KEY_HAS_VIDEO
  • _METADATA_KEY_HAS_LOCATION
  • _METADATA_KEY_HAS_MIMETYPE
  • _METADATA_KEY_NUM_TRACKS
  • _METADATA_KEY_TITLE
  • _METADATA_KEY_VIDEO_HEIGHT
  • _METADATA_KEY_VIDEO_ROTATION
  • _METADATA_KEY_VIDEO_WIDTH
  • _METADATA_KEY_WRITE
  • _METADATA_KEY_YEAR

Note

You can also use extractAllMetadata(): Promise to get some specified result like title, album, albumartist, artist, etc. as shown below

this.mmr.extractAllMetadata()
      .then((args) => {
          this.albumartist = args.albumartist;
          this.artist = args.artist; 
          this.author = args.author; 
          this.bitrate = args.bitrate;
          this.cdtracknumber = args.cdtracknumber;
          this.compilation = args.compilation; 
          this.composer = args.composer; 
          this.date = args.date; 
          this.disknumber = args.disknumber;
          this.duration = args.duration;
          this.genre = args.genre;
          this.hasaudio = args.hasaudio;
          this.haslocation = args.haslocation;
          this.hasmimetype = args.hasmimetype;
          this.hasvideo = args.hasvideo;
          this.numtracks = args.numtracks;
          this.title = args.title;
          this.videorotation = args.videorotation;
          this.width = args.width;
          this.write = args.write;
          this.year = args.year;
          ...
      });