Packagecom.wadedwalker.nativeExtension.media
Classpublic final class MediaMetadataRetriever
InheritanceMediaMetadataRetriever Inheritance Object

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The MediaMetadataRetriever class is a Native Extension built for the purpose of getting metadata from audio and video files. Currently in Flash, you can only get metadata after the audio/video file has started to play and, in video playback for example, you listen for the onMetaData event to retrieve information such as video width/height and the embedded image art.

For getting track information, use the extractMetadata method combined with the METADATA_KEY_XXXX constants for the type of data you want to retrieve.

This can work for a multitude of file types including, but not necessarily limited to: MP3, M4A, M4B, MP4.

NOTE: For Android, all metadata types require API Level 10 (Android 2.3.3 Gingerbread MR1) at minimum unless otherwise stated.

NOTE: Depending on the Android device, the app may temporarily pause while the data is being retrieved and the app will visually appear unresponsive. This seems to only occur on Nexus devices (Galaxy Nexus, Nexus 4, and Nexus 5 tested). It also seems to only happen on M4A and M4B files that are large in file size (greater than 50MB) although this could be based on the device running the app. MP3 files appear to be ok, even on Nexus devices.

View the examples



Public Properties
 PropertyDefined By
  AIR-only isSupported : Boolean
[static] [read-only] Deterimines whether or not this native extension is supported on the device the app is running on.
MediaMetadataRetriever
Public Methods
 MethodDefined By
  
MediaMetadataRetriever
  
AIR-only dispose():void
Properly shut down this Native Extension.
MediaMetadataRetriever
  
AIR-only extractAllMetadata(source:String):Vector.<String>
Retrieves all available metadata.
MediaMetadataRetriever
  
AIR-only extractMetadata(source:String, type:int):String
Retrieves the meta data value associated with the key code.
MediaMetadataRetriever
  
AIR-only getEmbeddedPicture(source:String):ByteArray
Attempts to get the embedded picture in the source file provided.
MediaMetadataRetriever
Public Constants
 ConstantDefined By
  AIR-only METADATA_KEY_ALBUM : int = 0x00000001
[static] The metadata key to retrieve the information about the album title of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_ALBUMARTIST : int = 0x0000000d
[static] The metadata key to retrieve the information about the performers or artist associated with the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_ARTIST : int = 0x00000002
[static] The metadata key to retrieve the information about the artist of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_AUTHOR : int = 0x00000003
[static] The metadata key to retrieve the information about the author of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_BITRATE : int = 0x00000014
[static] This key retrieves the average bitrate (in bits/sec), if available.
MediaMetadataRetriever
  AIR-only METADATA_KEY_CAPTURE_FRAMERATE : int = 0x00000019
[static] This key retrieves the original capture framerate, if it's available.
MediaMetadataRetriever
  AIR-only METADATA_KEY_CD_TRACK_NUMBER : int = 0x00000000
[static] The metadata key to retrieve the numeric string describing the order of the audio data source on its original recording.
MediaMetadataRetriever
  AIR-only METADATA_KEY_COMPILATION : int = 0x0000000f
[static] The metadata key to retrieve the music album compilation status.
MediaMetadataRetriever
  AIR-only METADATA_KEY_COMPOSER : int = 0x00000004
[static] The metadata key to retrieve the information about the composer of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_DATE : int = 0x00000005
[static] The metadata key to retrieve the date when the data source was created or modified.
MediaMetadataRetriever
  AIR-only METADATA_KEY_DISC_NUMBER : int = 0x0000000e
[static] The metadata key to retrieve the numberic string that describes which part of a set the audio data source comes from.
MediaMetadataRetriever
  AIR-only METADATA_KEY_DURATION : int = 0x00000009
[static] The metadata key to retrieve the playback duration of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_GENRE : int = 0x00000006
[static] The metadata key to retrieve the content type or genre of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_HAS_AUDIO : int = 0x00000010
[static] If this key exists the media contains audio content.
MediaMetadataRetriever
  AIR-only METADATA_KEY_HAS_VIDEO : int = 0x00000011
[static] If this key exists the media contains video content.
MediaMetadataRetriever
  AIR-only METADATA_KEY_LOCATION : int = 0x00000017
[static] This key retrieves the location information, if available.
MediaMetadataRetriever
  AIR-only METADATA_KEY_MIMETYPE : int = 0x0000000c
[static] The metadata key to retrieve the mime type of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_NUM_TRACKS : int = 0x0000000a
[static] The metadata key to retrieve the number of tracks, such as audio, video, text, in the data source, such as a mp4 or 3gpp file.
MediaMetadataRetriever
  AIR-only METADATA_KEY_TITLE : int = 0x00000007
[static] The metadata key to retrieve the data source title.
MediaMetadataRetriever
  AIR-only METADATA_KEY_VIDEO_HEIGHT : int = 0x00000013
[static] If the media contains video, this key retrieves its height.
MediaMetadataRetriever
  AIR-only METADATA_KEY_VIDEO_ROTATION : int = 0x00000018
[static] This key retrieves the video rotation angle in degrees, if available.
MediaMetadataRetriever
  AIR-only METADATA_KEY_VIDEO_WIDTH : int = 0x00000012
[static] If the media contains video, this key retrieves its width.
MediaMetadataRetriever
  AIR-only METADATA_KEY_WRITER : int = 0x0000000b
[static] The metadata key to retrieve the information of the writer (such as lyricist) of the data source.
MediaMetadataRetriever
  AIR-only METADATA_KEY_YEAR : int = 0x00000008
[static] The metadata key to retrieve the year when the data source was created or modified.
MediaMetadataRetriever
Property Detail
AIR-only isSupportedproperty
isSupported:Boolean  [read-only]

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Deterimines whether or not this native extension is supported on the device the app is running on.


Implementation
    public static function get isSupported():Boolean
Constructor Detail
MediaMetadataRetriever()Constructor
public function MediaMetadataRetriever()



Method Detail
AIR-only dispose()method
public final function dispose():void

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Properly shut down this Native Extension.

AIR-only extractAllMetadata()method 
public final function extractAllMetadata(source:String):Vector.<String>

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Retrieves all available metadata. Depending on the file, there could be a lot of data available or there could be very little.

Parameters

source:String — The File.nativePath property of the media file you want to get the metadata for.

Returns
Vector.<String> — Vector array containing the all available metadata information. Values will be presented as "KEY = value".
AIR-only extractMetadata()method 
public final function extractMetadata(source:String, type:int):String

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Retrieves the meta data value associated with the key code. If the desired metadata cannot be retrieved, it will return as an empty String. Use METADATA_KEY_XXXX constants for the type of data you want to retrieve.

Parameters

source:String — The File.nativePath property of the media file you want to get the metadata for.
 
type:int — The type of metadata to retrieve from the media source provided.

Returns
StringString containing the metadata information requested if it can be found. Returns null if there was an error trying to get the information.
AIR-only getEmbeddedPicture()method 
public final function getEmbeddedPicture(source:String):ByteArray

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

Attempts to get the embedded picture in the source file provided. The source file can be a audio or video file. If the embedded picture data can be found, it is returned as a ByteArray. From there, use the Loader display object to "load" the image using its loadBytes() method to load the image.

Depending on the device and file, the ByteArray may still be returned as non-null even if the embedded picture data cannot be found. Checking the ByteArray.length property would be a good way to check if there is actually any data. In testing, a value check of greater than 100 worked to see if there is truly data available.

Parameters

source:String — The File.nativePath property of the media file you want to get the embedded picture data for. Passing in the File.url property will most likely not work.

Returns
ByteArrayByteArray containing the BitmapData of the embedded picture data. Returns null if there was an error trying to get the embedded picture. If there are more than one pictures, (any) one of them is returned.
Constant Detail
AIR-only METADATA_KEY_ALBUMConstant
public static const METADATA_KEY_ALBUM:int = 0x00000001

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information about the album title of the data source.

See also

AIR-only METADATA_KEY_ALBUMARTISTConstant 
public static const METADATA_KEY_ALBUMARTIST:int = 0x0000000d

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information about the performers or artist associated with the data source.

See also

AIR-only METADATA_KEY_ARTISTConstant 
public static const METADATA_KEY_ARTIST:int = 0x00000002

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information about the artist of the data source.

See also

AIR-only METADATA_KEY_AUTHORConstant 
public static const METADATA_KEY_AUTHOR:int = 0x00000003

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information about the author of the data source.

See also

AIR-only METADATA_KEY_BITRATEConstant 
public static const METADATA_KEY_BITRATE:int = 0x00000014

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

This key retrieves the average bitrate (in bits/sec), if available.

NOTE: Requires API Level 14 (Android 4.0 Ice Cream Sandwich) or higher.

See also

AIR-only METADATA_KEY_CAPTURE_FRAMERATEConstant 
public static const METADATA_KEY_CAPTURE_FRAMERATE:int = 0x00000019

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

This key retrieves the original capture framerate, if it's available. The capture framerate will be a floating point number as a String.

NOTE: Requires API Level 23 (Android 6.0 Marshmallow) or higher.

See also

AIR-only METADATA_KEY_CD_TRACK_NUMBERConstant 
public static const METADATA_KEY_CD_TRACK_NUMBER:int = 0x00000000

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the numeric string describing the order of the audio data source on its original recording.

See also

AIR-only METADATA_KEY_COMPILATIONConstant 
public static const METADATA_KEY_COMPILATION:int = 0x0000000f

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the music album compilation status.

See also

AIR-only METADATA_KEY_COMPOSERConstant 
public static const METADATA_KEY_COMPOSER:int = 0x00000004

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information about the composer of the data source.

See also

AIR-only METADATA_KEY_DATEConstant 
public static const METADATA_KEY_DATE:int = 0x00000005

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the date when the data source was created or modified.

See also

AIR-only METADATA_KEY_DISC_NUMBERConstant 
public static const METADATA_KEY_DISC_NUMBER:int = 0x0000000e

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the numberic string that describes which part of a set the audio data source comes from.

See also

AIR-only METADATA_KEY_DURATIONConstant 
public static const METADATA_KEY_DURATION:int = 0x00000009

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the playback duration of the data source.

See also

AIR-only METADATA_KEY_GENREConstant 
public static const METADATA_KEY_GENRE:int = 0x00000006

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the content type or genre of the data source.

See also

AIR-only METADATA_KEY_HAS_AUDIOConstant 
public static const METADATA_KEY_HAS_AUDIO:int = 0x00000010

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

If this key exists the media contains audio content.

NOTE: Requires API Level 14 (Android 4.0 Ice Cream Sandwich) or higher.

See also

AIR-only METADATA_KEY_HAS_VIDEOConstant 
public static const METADATA_KEY_HAS_VIDEO:int = 0x00000011

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

If this key exists the media contains video content.

NOTE: Requires API Level 14 (Android 4.0 Ice Cream Sandwich) or higher.

See also

AIR-only METADATA_KEY_LOCATIONConstant 
public static const METADATA_KEY_LOCATION:int = 0x00000017

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

This key retrieves the location information, if available.

NOTE: Requires API Level 15 (Android 4.0.3 Ice Cream Sandwich MR1) or higher.

See also

AIR-only METADATA_KEY_MIMETYPEConstant 
public static const METADATA_KEY_MIMETYPE:int = 0x0000000c

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the mime type of the data source.

See also

AIR-only METADATA_KEY_NUM_TRACKSConstant 
public static const METADATA_KEY_NUM_TRACKS:int = 0x0000000a

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the number of tracks, such as audio, video, text, in the data source, such as a mp4 or 3gpp file.

See also

AIR-only METADATA_KEY_TITLEConstant 
public static const METADATA_KEY_TITLE:int = 0x00000007

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the data source title.

See also

AIR-only METADATA_KEY_VIDEO_HEIGHTConstant 
public static const METADATA_KEY_VIDEO_HEIGHT:int = 0x00000013

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

If the media contains video, this key retrieves its height.

NOTE: Requires API Level 14 (Android 4.0 Ice Cream Sandwich) or higher.

See also

AIR-only METADATA_KEY_VIDEO_ROTATIONConstant 
public static const METADATA_KEY_VIDEO_ROTATION:int = 0x00000018

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

This key retrieves the video rotation angle in degrees, if available.

NOTE: Requires API Level 17 (Android 4.2 Jelly Bean MR1) or higher.

See also

AIR-only METADATA_KEY_VIDEO_WIDTHConstant 
public static const METADATA_KEY_VIDEO_WIDTH:int = 0x00000012

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

If the media contains video, this key retrieves its width.

NOTE: Requires API Level 14 (Android 4.0 Ice Cream Sandwich) or higher.

See also

AIR-only METADATA_KEY_WRITERConstant 
public static const METADATA_KEY_WRITER:int = 0x0000000b

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the information of the writer (such as lyricist) of the data source.

See also

AIR-only METADATA_KEY_YEARConstant 
public static const METADATA_KEY_YEAR:int = 0x00000008

Language Version : ActionScript 3.0
Runtime Versions : AIR 2.5

The metadata key to retrieve the year when the data source was created or modified.

See also

Examples
The following example shows how to get the embedded cover art image (if available) in a media file. This example assumes that you already have a reference to a media file with a File object variable named "mediaFile".
package {
    
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import com.wadedwalker.nativeExtension.media.MediaMetadataRetriever;
    
    final public class MyAndroidApp extends Sprite {
        
        private var _mmr:MediaMetadataRetriever;
        prviate var _loader:Loader;
        
        final public function MyAndroidApp() {
            _mmr = new MediaMetadataRetriever();
            _loader = new Loader();
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onCoverArtLoaded);
            // load the ByteArray of the cover art image
            // if there is more than 1 cover art asset in this media file, the first one will be loaded
            _loader.loadBytes(_mmr.getEmbeddedPicture(mediaFile.nativePath));
        }
        
        final private function _onCoverArtLoaded(e:Event):void {
            _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, _onCoverArtLoaded);
            this.addChild(_loader.content);
        }
    }
}
    
The following example shows how to get multiple bits of information from an assumed audio file and adding that data to a TextField to present the info. This example assumes that you already have a reference to a media file with a File object variable named "mediaFile".
package {
    
    import flash.display.Sprite;
    import flash.text.TextField;
    import com.wadedwalker.nativeExtension.media.MediaMetadataRetriever;
    
    final public class MyAndroidApp extends Sprite {
        
        private var _mmr:MediaMetadataRetriever;
        prviate var _songInfo:TextField;
        
        final public function MyAndroidApp() {
            _songInfo = new TextField();
            this.addChild(_songInfo);
            _mmr = new MediaMetadataRetriever();
            _songInfo.appendText("Title: " + _mmr.extractMetadata(mediaFile.nativePath, MediaMetadataRetriever.METADATA_KEY_TITLE) + "\n");
            _songInfo.appendText("Album: " + _mmr.extractMetadata(mediaFile.nativePath, MediaMetadataRetriever.METADATA_KEY_ALBUM) + "\n");
            _songInfo.appendText("Artist: " + _mmr.extractMetadata(mediaFile.nativePath, MediaMetadataRetriever.METADATA_KEY_ARTIST) + "\n");
            _songInfo.appendText("Track #" + _mmr.extractMetadata(mediaFile.nativePath, MediaMetadataRetriever.METADATA_KEY_CD_TRACK_NUMBER) + "\n");
        }
    }
}