Media files often contain metadata. This extension extracts metadata from media files and makes them available. The metadata can be extracted from physically existing files as well as from streaming files (e.g. "https://...mp3). All data can be completed by program.
The UrsMediaNotification extension can accept the retrieved metadata directly (later !!!). An album image contained in the metadata can be saved or passed directly to an Image component.
Version | Adjustments |
---|---|
1.0 (2021-07-06) | Initial version |
1.1 (2024-09-04) | Adaptations to Android 14 |
The UrsAI2MediaHelper ZIP archive for download. The archive contains the source code, the compiled binary for uploading to the App Inventor and a sample application.
The extension is a wrapper for the Android MediaMetadataRetriever class.
A test file with metadata is available at the address https://ullisroboterseite.de/test.mp3. The example contains the same file as an asset file.
The main methods are LoadMetaData and LoadMetaDataAsync. These two methods extract the metadata from a media file. The following values are valid for the Source parameter :
Type | Prefix | Example |
---|---|---|
URL | http or https | https://ullisroboterseite.de/test.mp3 |
Asset | // or nothing | //test.mp3 or test.mp3 |
File, relative path | / | /data/user/0/edu.mit.appinventor.aicompanion3/test.mp3 |
File, absolute path | file:/// | file:///Android/data/edu.mit.appinventor.aicompanion3/test.mp3 |
If an invalid file specification is entered, the specified file does not exist or is not a media file, it can take up to 30 seconds for the MediaMetadataRetriever to recognize this and return. This is especially true when the files are obtained from the Internet. The Timeout property can be used to define the maximum time to wait for the response.
LoadMetaData waits for the response from the MediaMetadataRetriever and returns whether the process was successful. The application remains inactive for this time. LoadMetaDataAsync loads the metadata in a separate thread and reports the result via the AfterLoadMetaData event. The application remains active while the metadata is being retrieved. However, you have to make sure that you do not access the data before the event has been triggered with the parameter Success = true.
Note: It is not the case that all metadata is always present in each media file.
The following values are valid for property AlbumImageFile;
Type | Prefix | Example |
---|---|---|
URL | http or https | https://ullisroboterseite.de/ulli.png |
Asset | // or nothing | //ulli.png or ulli.png |
File, relative path | / | /data/user/0/edu.mit.appinventor.aicompanion3/ulli.png |
Fiel, absolute path | file:/// | file:///Android/data/edu.mit.appinventor.aicompanion3/ulli.png |
When specifying an URL, the image is loaded synchronously. This can take some time with large files or slow connections. Another possibility is to use an extension that enables an asynchronous (concurrent) download of the file ( e.g. the ImageLoader extension ).
The properties AlbumImageWidthDip, AlbumImageHeightDip, AlbumImageWidthRaw and AlbumImageHeightRaw return informations on the size of the graphic. The size of the graphic can be adjusted with the methods ResizeAlbumImageDip or ResizeAlbumImageRaw. The SaveAlbumImage and SaveAlbumImageToAppDir methods save the graphic as a file and can be made available to other file-based components.
The ToImageBlock method displays the graphic in the specified Image component.
For an easy access to files you can use:
Errors are reported via the Screen.ErrorOccurred event.
Code | Text | Bedeutung | Anmerkung |
---|---|---|---|
17510 | Album image not found. | The specified album image could not be loaded. | Affected function is AlbumImageFile. |
17511 | Invalid size. | Invalid size, width or height ≤ 0. | Affected functions are ResizeAlbumImageDip and ResizeAlbumImageRaw. |
17512 | IO error & Fehlergrund. | File could not be written or deleted. | Affected functions are SaveAlbumImage, SaveAlbumImageToAppDir, RemoveFile and RemoveFileFromAppDir. |
17513 | Invalid format. | The value for parameter Format is invalid. 0 or 1 is allowed. | Affected functions are SaveAlbumImage and SaveAlbumImageToAppDir. |
17514 | Invalid component type. | The specified component is not of type Image. | Affected function is ToImageBlock. |
GetAppDataDir()
on my test
device (in the example below) returns the following result:GetDownloadDir("file://")
on my test device (in the example below)
returns the following result: GetFileList(GetAppDataDir())
on my test device for the example program returns a list
with the following elements: getVolumes("file://)
on my test device returns the following items : The download archive contains a sample project:
MediaHelper Test
The example can load media metadata synchronously (Load Media Metadata) and asynchronously (Load Media Metadata async). The album image can be saved in the private folder of the app (Save album image) and deleted (Remove file). The List files button lists the files in the app's private folder.
I have collected a few tips for creating your own extensions: AI2 FAQ: Developing extensions .