如何从互联网上为音乐播放器项目获取/下载专辑封面

时间:2019-03-30 18:37:44

标签: vb.net

您好,我正在制作音乐播放器,外观整洁,设计出色,我即将完成,但是我想添加一个很酷的智能功能,那就是当互联网连接且mp3中没有专辑封面时文件(“歌曲”),则程序应下载并按mp3文件的名称获取封面,如果mp3文件中有封面,请使用它(我已经做到了)。我所不知道的就是知道我在这段代码中做错了什么。问题是出现Msgbox,并说为什么下载歌曲封面时出错。我的代码有问题吗?并感谢您的时间和对我的帮助:)

''label13和labell5是歌曲名称 ”如果可以访问互联网,请下载封面

    If My.Computer.Network.IsAvailable Then

        Label13.Text = Label5.Text
        Dim Clint As New WebClient()
        Dim photolink As String = Nothing

        Application.DoEvents()
        Dim sourceCollection As String = Clint.DownloadString(New Uri("https://www.amazon.com/s?k=" + Label13.Text + "&i=digital-music&ref=nb_sb_noss"))
        Dim Weber As New WebBrowser With {.ScriptErrorsSuppressed = True}
        Weber.DocumentText = sourceCollection
        Dim htmlColl As HtmlDocument = Weber.Document.OpenNew(True)
        htmlColl.Write(sourceCollection)
        If htmlColl.GetElementById("mp3StoreShovelerCell0") IsNot Nothing Then
            Dim theHtmlElementCollection As HtmlElementCollection = htmlColl.GetElementById("mp3StoreShovelerCell0").GetElementsByTagName("img")
            For Each curElement As HtmlElement In theHtmlElementCollection
                photolink = curElement.GetAttribute("src")
            Next
            If photolink IsNot Nothing Then
                photolink = photolink.ToString.Replace("._SL500_SS110_.jpg", "._SS500_.jpg")
                BunifuImageButton2.ImageLocation = photolink



            End If
        Else
            BunifuImageButton2.Image = My.Resources.clipart536736

            MsgBox("Error in Downloading Song Cover")

        End If

    Else
        Dim file As TagLib.File = TagLib.File.Create(AxWindowsMediaPlayer1.URL.ToString())
        If (file.Tag.Pictures.Length > 0) Then
            Dim bin = CType(file.Tag.Pictures(0).Data.Data, Byte())
            BunifuImageButton2.Image = Image.FromStream(New MemoryStream(bin)).GetThumbnailImage(600, 600, Nothing, IntPtr.Zero)

            BunifuImageButton7.Image = Image.FromStream(New MemoryStream(bin)).GetThumbnailImage(600, 600, Nothing, IntPtr.Zero)
        Else
            BunifuImageButton7.Image = My.Resources.clipart536736

        End If
    End If
    BunifuImageButton7.Image = BunifuImageButton2.Image
    ''end of code cover

0 个答案:

没有答案