0

我正在从 c#.net 为我的歌曲文件夹中的所有歌曲创建一个 xml 文件。我的代码如下:

 Microsoft.MediaPlayer.Interop.IWMPMedia mediafilesinformation = plist.get_Item(i);
                   mediafilesinformation = obj_wmp.newMedia(filepath);
                    Filename = mediafilesinformation.getItemInfo("SourceURL");
                    Tracknumber = mediafilesinformation.getItemInfo("WM/TrackNumber");
                    Genre = mediafilesinformation.getItemInfo("WM/Genre");
                    Album = mediafilesinformation.getItemInfo("WM/AlbumTitle");
                    Artist = mediafilesinformation.getItemInfo("Artist");
                    Name = mediafilesinformation.getItemInfo("Name");
                    Duration = double.Parse(mediafilesinformation.getItemInfo("Duration"));

我在名称中获得了歌曲的标题,但我必须获得歌曲的名称。请建议我解决方案。

4

2 回答 2

0

如果您需要,属性中的 Name 属性指向 FileName,然后您可以使用文件路径字符串。

string fileName = Path.GetFileName(filepath);

您还可以打印出所有属性,调试它们并查看属性所持有的值。使用Media.getAttributeName 方法。来自同一链接的示例如下:

// Store the current media object.
var cm = Player.currentMedia;

// Get the number of attributes for the current media. 
var atCount = cm.attributeCount;

// Loop through the attribute list.
for(var i=0; i < atCount; i++){

   // Print each attribute index and name.   
   myText.value += "Attribute " + i +": ";
   myText.value += cm.getAttributeName(i);
   myText.value += "\n";
}
于 2012-04-21T10:07:14.830 回答
0

按照这些参考链接和代码片段..希望这有帮助

参考:在不实际播放剪辑的情况下获取音频或视频剪辑的持续时间

Microsoft.MediaPlayer.Interop.IWMPMedia m = Player.newMedia(fileName);

string currentArtist = m.getItemInfo("Author").Trim();
string currentAlbum = m.getItemInfo("Album").Trim();
string currentTitle = m.getItemInfo("Title").Trim();
double duration = m.duration; 

参考:链接

Microsoft.MediaPlayer.Interop.IWMPPlaylist plist; 
plist = x.mediaCollection.getAll();                        

for(int i=0; i < plist.count;i++) 
{ 
        Microsoft.MediaPlayer.Interop.IWMPMedia elem = plist.get_Item(i); 

        Response.Write(string.Format("{1} - {2} - {3} - {4} - {5}
", 
                elem.sourceURL, 
                elem.name, 
                elem.getItemInfo("MediaType"), 
                elem.getItemInfo("FileType"), 
                elem.getItemInfo("WM/TrackNumber"), 
                elem.getItemInfo("Author"), 
                elem.getItemInfo("Title") 
        )); 
} 
于 2012-04-21T10:24:04.090 回答