Basically I'm despaired.
I've tried everything I've seen on every Google result concerning this problem.
I have a program that is very similar to WMP. It's using axWMP control to play songs and etc.
I've got many types of audio files, mp3, m4a, wma, etc. I've successfully coded something to get the tags: track#, title, album, artist, year. The only thing I can't seem to get correctly done is the album art.
The code I'm using only works for some mp3 files. Of course it's because I'm using UltraID3 and that would only work for mp3.
Here's the code:
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
But then I tried fetching the album art through the WMP control itself, just like I did for the rest of the tags :
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
This function goes into the internet explorer temp folder and copy the image outside in order to use it. It works, but then again only for the same mp3 files.
I've read about the Apple Quick Time control I could use for m4a files, but I couldn't get anything out of it.
One thing that really bothers me is that it works for mp3 but not all of them.
The only clues I have to why it's not working are : "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" on line MP3Tag.Read(path) above and "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" on line pic = tWMP.currentMedia.getItemInfoByType("WM/Picture", "", i) for whenever the file is a not working mp3 or other file format.
I know it's not impossible as WMP 12 itself displays the album arts for any file just fine.
Thanks for helping me out.