How to Load Media Artwork for any Music Album, Video... Into a PictureBox Lightning Fast and Get Results Every Time

  • Thread starter Thread starter Larry G. Robertson
  • Start date Start date
L

Larry G. Robertson

Guest
I had to go Old School on this one after hours or trying to figure out a way without using any controls, just a WebClient and Strings. I wanted the method to be completely thread safe as well. The demo application below allows you to type in any search string (i.e. Title, Artist and Album Strings all together) into the Search TextBox and click search.

You can easily concatenating this data by using WMPLib's


Player.currentMedia.getItemInfo("title") & " " & UIForm.Player.currentMedia.getItemInfo("artist") & " " & UIForm.Player.currentMedia.getItemInfo("album")
The resulting image will be displayed in the PictureBox. (This is not a question it is only FYI)


Imports System.Net

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBoxSearch.Text = "put it on paper al green & ann nesby Body + Soul Duets Disc 1"
End Sub
Private Sub ButtonSearch_Click(sender As Object, e As EventArgs) Handles ButtonSearch.Click

Dim client As New WebClient
Dim photoLink As String = Nothing
Dim strSeachableSongName As String = ""
If TextBoxSearch.Text.Contains(" ") Then
strSeachableSongName = EscapeURI("cd dvd " & TextBoxSearch.Text)
strSeachableSongName += "&oq=" & strSeachableSongName
strSeachableSongName = strSeachableSongName.Replace("%20", "+")
End If
Dim strURI As String = "Google Images"
strURI += strSeachableSongName
strURI += "&gs_l=img.3...2705.2705..3141...0.0..0.58.58.1......0....1..gws-wiz-img.n7mM1Ax2zM8"
Dim SourceCollection As String = client.DownloadString(New Uri(strURI))
Dim intStartPosition As Integer = 0
Dim intStartPositionSRC As Integer = 0
Dim intEndPosition As Integer = 0
Dim strHTML As String = Nothing
Try
intStartPosition = InStr(1, SourceCollection, "<img")
strHTML = SourceCollection.Substring(intStartPosition - 1)
intEndPosition = InStr(1, strHTML, "</img>")
strHTML = strHTML.Substring(0, strHTML.Length - 6)
intStartPosition = InStr(1, strHTML, "src=")
strHTML = strHTML.Substring(intStartPosition - 1)
intStartPosition = InStr(1, strHTML, "http")
intEndPosition = InStr(intStartPosition, strHTML, """")
Dim strImageLink As String = strHTML.Substring(intStartPosition - 1, intEndPosition - intStartPosition)
PictureBoxCover.ImageLocation = strImageLink
Catch ex As Exception

End Try

End Sub

Private Function EscapeURI(pstrURI As String) As String
EscapeURI = ""
Dim strReturn As String = pstrURI
Dim strReturn1 = strReturn.Replace("%", "%25")
Dim strReturn2 = strReturn1.Replace("&", "%26")
Dim strReturn3 = strReturn2.Replace("$", "%24")
Dim strReturn4 = strReturn3.Replace("+", "%2b")
Dim strReturn5 = strReturn4.Replace(" ", "%20")
Dim strReturn6 = strReturn5.Replace("<", "%3c")
Return strReturn6
End Function

End Class

Continue reading...
 
Back
Top