Metadata
You can extract metadata information from multimedia files. Metadata is the information about multimedia files.
The main features of the Metadata API include:
-
Extracting simple metadata informations
You can extract metadata from multimedia files using
get()
. -
Extracting artwork of a multimedia file
You can extract artwork from multimedia files using
getArtwork()
to get the Blob object containing the artwork. -
Extracting thumbnail frame of a video file
You can extract thumbnail frame from video files using
getThumbnailFrame()
to get the Blob object containing the frame. -
Extracting frame of a video file for a specified time
You can extract certain frame from video files using
getFrameAtTime()
to get the Blob object containing the frame. -
Extracting synchronized lyrics of a multimedia file
You can extract lyrics from multimedia files using
getSyncLyrics()
to get timestamp and lyrics pairs.
Prerequisites
To access files using the Metadata API (in mobile, wearable, and TV applications), the application has to request storage privileges by adding the following privileges to the config.xml
file:
<!-- for accessing internal storage only -->
<tizen:privilege name="http://tizen.org/privilege/mediastorage"/>
<!-- for accessing external storage only -->
<tizen:privilege name="http://tizen.org/privilege/externalstorage"/>
Additionally, to access files using the Metadata API (in mobile and wearable applications), the application has to request proper storage permissions using the PPM API (in mobile and wearable applications).
Extract metadata
-
Create a file handle using
createFileHandle()
:var filePath = "videos/sample_video.mp4"; var fileHandle = tizen.metadata.createFileHandle(filePath);
-
When the file handle is created, metadata can be extracted:
console.log("Video duration is: " + fileHandle.get("DURATION") + " milliseconds"); console.log("Video title is: " + fileHandle.get("TITLE"));
-
For better performance, the file handle does not release underlying resources after every metadata extraction. The data is decoded on the first extraction, which helps in speeding up the next metadata extractions. When all the needed metadata is extracted, the file handle needs to be released using
release()
:fileHandle.release();
Extract artwork
-
Create a file handle using
createFileHandle()
. Ensure your file includes an artwork.var filePath = "music/sample.mp3"; var fileHandle = tizen.metadata.createFileHandle(filePath);
-
When the file handle is created, artwork can be extracted:
var artwork = fileHandle.getArtwork();
-
Blob object can be easily shown in your application in html <img> tag
var elem = document.getElementById("blobImage"); elem.src = URL.createObjectURL(artwork);
-
After use, release the file handle.
Extract thumbnail frame
-
Create a file handle using
createFileHandle()
for a video file.var filePath = "videos/sample_video.mp4"; var fileHandle = tizen.metadata.createFileHandle(filePath);
-
When the file handle is created, thumbnail frame can be extracted:
var thumbnail = fileHandle.getThumbnailFrame();
-
Blob object can be easily shown in your application in html <img> tag
var elem = document.getElementById("blobImage"); elem.src = URL.createObjectURL(thumbnail);
-
After use, release the file handle.
Extract certain frame
-
Create a file handle using
createFileHandle()
for a video file.var filePath = "videos/sample_video.mp4"; var fileHandle = tizen.metadata.createFileHandle(filePath);
-
When the file handle is created, thumbnail frame can be extracted. You need to provide timestamp information (in milliseconds) and a flag indicating accuracy. When the flag value is set to
true
, flag indicates extracting an exact frame for the given time. When the value isfalse
, flag indicates extracting an I-frame nearest to the given time. Gathering nearest I-frame has better performance.var timestamp = 2000; var returnExactFrame = true; var frame = fileHandle.getFrameAtTime(timestamp, returnExactFrame);
-
Blob object can be easily shown in your application in html <img> tag
var elem = document.getElementById("blobImage"); elem.src = URL.createObjectURL(frame);
-
After use, release the file handle.
Extract lyrics
-
Create a file handle using
createFileHandle()
. Lyrics need to be included in multimedia file as SYLT metadata tag. Supported formats of encoding are at least UTF-8 and ISO-8859-1. Other formats can be ignored depending on the platform.var filePath = "music/sample.mp3"; var fileHandle = tizen.metadata.createFileHandle(filePath);
-
When the file handle is created, check how many lyrics are included.
var lyricsNum = fileHandle.get("SYNCLYRICS_NUM");
-
Gather and print the lyrics:
for (var i = 0; i < lyricsNum; ++i) { var lyrics = fileHandle.getSyncLyrics(i); console.log("Lyrics " + i + " (" + lyrics.timestamp + "ms): " + lyrics.lyrics); }
-
After use, release the file handle.
Related Information
- Dependencies
- Tizen 6.0 and Higher for Mobile
- Tizen 6.0 and Higher for Wearable
- Tizen 6.0 and Higher for TV