Media_ExtractInfo ( infoList ; retrievalKey )
Media_ExtractInfo allows you to easily extract specific pieces of information from an information list of any format.
Parameter | Description |
---|---|
infoList | The information list, a text field or expression. |
retrievalKey | Either the retrieval key or the line number of the item to be returned (see below) |
This function extracts the value of a field in from an information list, such as the values returned by Media_GetImageInfo, Media_GetSoundInfo, Media_GetItemInfo, Media_ListEffects, Media_ListFolder, etc.
Media_ExtractInfo works with both simple lists and key-value pairs.
Simple Lists
Simple lists are just lists separated by carriage returns. Here’s an example of a simple list:
Apples
Oranges
Lychees
Papayas
Fruit Salad
If the above list is contained in a field named “Fruit Options,” you can easily retrieve “Oranges” – the second value – by passing a retrieval key value of 2:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Fruit Options; 2
) ]
Key – Value Pairs (Basic)
Media_ExtractInfo can also work with key and value pairs. Simple example would be:
Height: 6 ft. 2 in.
Weight: 155 lbs
Suppose in this example you want to get the weight value. Instead of using a retrieval key of “2” (which would return the entire second line), you can send a retrieval key of “Weight” to get the response “155 lbs”:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Size;
"Weight"
) ]
This is especially useful to extract data from Media_GetImageInfo function’s results.
Key – Value Pairs (Hierarchical Structures)
In addition, Media_ExtractInfo can also handle more complex hierarchical structures. For example, the Media_GetSoundInfo function returns an indented hierarchical response, such as:
Format: AIFF
Track 1
Volume: 256
Duration (s): 000:00:01.207
Creation Date (ts): 22-08-2005 12:39:43
Modification Date (ts): 22-08-2005 12:39:43
Media
Media Duration (s): 000:00:01.207
Media Creation Date (ts): 22-08-2005 12:39:43
Media Modification Date (ts): 22-08-2005 12:39:43
Media Language: 0
Media Quality: 0
Sample Description 1
Sample Format: 74776F73
Number of Channels: 2
Sample Size (b): 16
Sample Rate (Hz): 44100
If you just want to know that the format is “AIFF”, all you need to do is send a basic retrieval key:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Sound Info ;
"Format"
) ]
But suppose you want to find out the volume for Track 1. In that case, you would need a hierarchical retrieval key of “Track 1/Volume”:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Sound Info ;
"Track 1/Volume"
) ]
This approach works the same even for deeper levels of the hierarchy. For example, to get the number of channels (whether it is a mono or stereo sound file), you would use “Track 1/Media/Sample Description 1/Number of Channels” for your retrieval key.
Units Designator
In some cases, the key in the info list may include a units or type designator, such as “(s)” for seconds, etc. Media_ExtractInfo does not require you to list the designator as part of your retrieval key. For example, in the above sound info example, you can use —
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Sound Info ;
"Track 1/Duration"
) ]
— to get the length of the sound clip. You do not need to use “Track 1/Duration (s)” as the retrieval key.
List Count
If you want Media_ExtractInfo to give you a count of the number of items in the list, just leave the retrieval key parameter empty. For example:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
MyTable::Sound Info ; ""
) ]
Non-Carriage Return Separators
Many information lists, of course, do not use carriage returns as separators. They may instead be separated by commas, pipe characters, etc. In order to allow Media_ExtractInfo to work with these lists, all you have to do is use FileMaker Pro’s Substitute function to substitute a carriage return for the separator character.
For example, suppose you have a field named Items that contains a list separated by commas, and you want to extract the third item. You can use the Substitute function like this:
Set Field [ MyTable::Response ;
Media_ExtractInfo (
Substitute (
MyTable::Items ; # comma sep. list
"," ;# replace commas
"¶"# with newlines
) ;
3# take third line
) ]
Returns
Media_ExtractInfo returns the value associated with the key or index. If the value represents a time, date, or timestamp, the appropriate FileMaker type is returned. Otherwise, text is returned.