MetaDataControl允許我們從媒體流中收集元數據信息。元數據保存的信息通常包括:藝術家、專輯、歌曲名或者文件的創建者放在其中的其它任何信息。
這個功能存在于移動媒體API(JSR135)中,并且是在Sony EriCSSon javaTM Platform6(JP-6)移動電話(當前有W550、W600、W810和W900)上新支持的接口之一。
MetaDataControl接口十分簡單,定義時只需要兩個方法:
public java.lang.String[] getKeys()
public java.lang.String getKeyValue(java.lang.String key)
同所有其它類型的控制一樣,它可以從播放器類中通過getControl方法獲得,然而播放器關閉或者處于不可知狀態時就不能獲得了。
MetaDataControl mc = (MetaDataControl) p.getControl("MetaDataControl");
MetaDataControl中的元數據按照String鍵值對的形式存儲,即一個字符串是鍵(key),另外一個是值(value)。例如,對于mp3文件fight_the_power.mp3,“artist”鍵的值可能是“public enemy”。
為了從媒體文件中獲得已經存在的key,可以使用getKeys方法:
String[] metaKeys= mcd.getKeys();
如果我們已經獲得一個鍵,要獲得它的值時,可以使用getKeyValue方法:
String aMetavalue = mcd.getKeyValue(metaKeys[0]);
// Create the Player
Player p = Manager.createPlayer("http://abc.mpg");
// acquiring resources
p.PRefetch();
// Create a reference for the MetaDataControl
MetaDataControl mc;
// Retrieve the MetaDataControl from the Player
mc = (MetaDataControl) p.getControl("MetaDataControl");
// Get the keys for the meta data information
String[] metaKeys= mcd.getKeys();
// Create a String array for the meta data inforamtion
String[] aMetavalue = new String[metaKeys.length];
// Retrieve the meta data values and print them out to
for(int i=0; i
{
metaInfo[i]=mcd.getKeyValue(metaKeys[i]);
System.out.println(metaInfo[i]);
}
例子源代碼、原文地址
(出處:http://www.49028c.com)
新聞熱點
疑難解答