如何从OpenFileDialog获取专辑,歌手等

时间:2018-11-15 12:23:45

标签: vb.net

我基本上是在vb.net中制作音频播放器,用户可以在其中使用openfiledialog上传文件,然后再播放。我想从我上传的歌曲中收集一些元数据,例如要显示的专辑和歌手。

我环顾四周,但似乎找不到任何有关此问题的信息,如果有人有任何想法,将不胜感激。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button_Upload.Click
    OpenFileDialog1.InitialDirectory = "C:\"
    OpenFileDialog1.Title = "Upload A Song"
    OpenFileDialog1.Filter = "Audio Files|*.mp3; *.wav"
    OpenFileDialog1.Multiselect = False




    If OpenFileDialog1.ShowDialog = DialogResult.OK Then

        Dim Upload_Path As String = IO.Path.Combine(Application.StartupPath, "Resources")

        If IO.Directory.Exists(Upload_Path) Then

            IO.File.Copy(OpenFileDialog1.FileName, IO.Path.Combine(Upload_Path, IO.Path.GetFileName(OpenFileDialog1.FileName)))
        Else
            System.IO.Directory.CreateDirectory(Upload_Path)
            IO.File.Copy(OpenFileDialog1.FileName, IO.Path.Combine(Upload_Path, IO.Path.GetFileName(OpenFileDialog1.FileName)))
        End If


    Else
        MsgBox("Invalid Selection")
    End If

End Sub

1 个答案:

答案 0 :(得分:0)

签出taglib-sharp。它支持从多种格式中读取信息。

Dim tfile = TagLib.File.Create("C:\My audio.mp3");
Dim title As String = tfile.Tag.Title;
Dim duration As TimeSpan = tfile.Properties.Duration;
Console.WriteLine("Title: {0}, duration: {1}", title, duration);