您现在的位置: J2ME开发网 >> Java技术 >> J2ME开发 >> J2ME可选包 >> 文章正文
使用MetaDataControl从媒体流中收集元数据
作者:mydeman编…    文章来源:本站原创    点击数:    更新时间:2006-3-10

MetaDataControl允许我们从媒体流中收集元数据信息。元数据保存的信息通常包括:艺术家、专辑、歌曲名或者文件的创建者放在其中的其它任何信息。

这个功能存在于移动媒体APIJSR135)中,并且是在Sony Ericsson JavaTM Platform6JP-6)移动电话(当前有W550W600W810W900)上新支持的接口之一。

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]);      
}

例子源代码原文地址