0

基本上我很绝望。

我已经尝试了所有关于这个问题的谷歌搜索结果。

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

我有许多类型的音频文件,mp3、m4a、wma 等。我已经成功地编写了一些代码来获取标签:曲目#、标题、专辑、艺术家、年份。我似乎无法正确完成的唯一一件事是专辑封面。

我使用的代码仅适用于某些 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 文件的 Apple Quick Time 控件,但我无法从中得到任何东西。

真正困扰我的一件事是它适用于 mp3 但不是全部。

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

我知道这并非不可能,因为 WMP 12 本身可以很好地显示任何文件的专辑封面。

谢谢你的协助。

4

1 回答 1

0

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

于 2015-02-10T20:58:38.473 回答