2015-01-21 112 views
0

基本上我很绝望。VB.Net - 音频文件专辑艺术

我已经试过了所有关于此问题的Google搜索结果。

我有一个与WMP非常相似的程序。它使用axWMP控制播放歌曲等。

我有很多类型的音频文件,mp3,m4a,wma等。我已经成功编码了一些东西以获取标签:track#,title,album,艺术家,年。我似乎无法正确完成的唯一事情就是专辑封面。

我使用的代码仅适用于某些mp3文件。当然,这是因为我使用的是UltraID3,而这只适用于mp3。

下面的代码:

   Dim MP3Tag As New UltraID3 

      albumArt = Nothing 

      Try 
       MP3Tag.Read(path) 
       Try 
        Dim pics = MP3Tag.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture) 
        albumArt = CType(pics(0), ID3v2PictureFrame).Picture 
       Catch ex As Exception 
        'albumArt = FetchAlbumImage(j, path) 
       End Try 
      Catch ex As Exception 
      End Try 

但后来我试图通过WMP控件本身获取的专辑封面,就像我做了标记的其余部分:

Function FetchAlbumArt(index As Integer, filePath As String) As Image 

    FetchAlbumArt = Nothing 

    Dim pic As WMPLib.IWMPMetadataPicture = Nothing 

    Dim tWMP As New WindowsMediaPlayer 

    tWMP.currentMedia = Me.WMP.currentPlaylist.Item(index) 

    For i = 0 To tWMP.currentMedia.getAttributeCountByType("WM/Picture", "") 
     Try 
      pic = tWMP.currentMedia.getItemInfoByType("WM/Picture", "", i) 
      Exit For 
     Catch ex As Exception 
      Debug.Print(Err.Description) 
     End Try 
    Next 

    If Not IsNothing(pic) Then 

     Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) 
     Dim fInfo, fInfos() As IO.FileInfo 
     Dim dInfo As IO.DirectoryInfo 

     dInfo = New IO.DirectoryInfo(path) 
     fInfos = dInfo.GetFiles("*" & FindStringBeforeLastIndexOfChar(FindStringAfterLastIndexOfChar(pic.URL, "/"), ".", False) & "*", IO.SearchOption.AllDirectories) 

     For Each fInfo In fInfos 
      If fInfo.Name Like "*" & FindStringBeforeLastIndexOfChar(FindStringAfterLastIndexOfChar(pic.URL, "/"), ".", False) & "*" Then 
       System.IO.File.Copy(fInfo.FullName, dbFolderPath & "\temp.jpg", True) 
      End If 
     Next 

     Dim albumArt As Image 
     albumArt = Bitmap.FromFile(dbFolderPath & "\temp.jpg") 

     FetchAlbumArt = albumArt 

    End If 

End Function 

此功能去进入Internet Explorer临时文件夹并将图像复制到外部以便使用它。它的工作原理,但只为相同的MP3文件。

我读过关于苹果快速时间控制我可以用于m4a文件,但我什么也得不到。

真正困扰我的一件事是,它适用于mp3,但不是所有的。

我唯一的线索为什么它不起作用:“索引超出范围,必须是非负数,小于集合的大小。” 参数名称:index“on line MP3Tag.Read(path )上面和“参数是不正确的(从HRESULT异常:0x80070057(E_INVALIDARG))”在线pic = tWMP.currentMedia.getItemInfoByType(“WM/Picture”,“”,我)每当文件是不工作的MP3或其他文件格式。

我知道这不是不可能,因为WMP 12本身显示任何文件的专辑艺术就好了。

感谢您的帮助。

回答

0

WMP将其专辑封面存储在%LOCALAPPDATA%\Microsoft\Media Player\Art Cache\LocalMLS文件夹中。此文件夹中JPEG文件的文件名与库中WMP媒体项目的TrackingID属性相对应。

相关问题