Geschwindigkeitsproblem bei ID3-Erkennung

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von jvbsl.

    Geschwindigkeitsproblem bei ID3-Erkennung

    Hallo zusammen,

    ich habe ein kleines Problem mit einer Software die ich aktuell erstelle..
    Ich habe zwar in der Suche geschaut, aber nichts gefunden, also bitte den Kopf nicht abreißen :D

    Ich baue aktuell einen kleinen PC für mein Auto und entwickle dafür gerade die Software.
    Nun hänge ich grade bei der Multimedia-Sektion ...

    Das Programm soll alle MP3 Dateien aus einem vorgegebenen Ordner auslesen und in die Mediathek (vorerst eine kleine Tabelle) einreihen.

    Den Code hierzu habe ich zwar, nur dauert es Ewigkeiten ...
    Selbst das erkennen von 1 Album á 60 Tracks dauert eine gute halbe Minute, das ist mir zu viel.

    VB.NET-Quellcode

    1. 'Form1
    2. '[...]
    3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4. Form2.Show()
    5. Form2.GetMusic()
    6. End Sub
    7. '[...]
    8. 'Form2
    9. Imports System.IO
    10. Imports System.Text
    11. Imports System.String
    12. Public Class Form2
    13. Dim File, Files() As FileInfo
    14. Dim Mp3File As Object = CreateObject("Scripting.FileSystemObject")
    15. Dim searchtype As String = "*.mp3"
    16. Dim nr As Integer = 0
    17. Dim c As Integer = 0
    18. Dim sBuffer As String
    19. Dim Str As String
    20. Dim MyString(127) As String
    21. Dim alltitles(0 To 50000) As String
    22. Dim allartists(0 To 50000) As String
    23. Dim allalbums(0 To 50000) As String
    24. Dim allalbumyears(0 To 50000) As String
    25. Dim title, artist, album, albumyear, comment, genre As String
    26. Private Property Folders As ObjectModel.ReadOnlyCollection(Of String)
    27. Dim FSO As Object
    28. Dim nrs As String = ""
    29. Public Sub GetMusic()
    30. BackgroundWorker1.RunWorkerAsync()
    31. End Sub
    32. Public Sub GetFiles(ByVal dir As String, ByVal type As String)
    33. Dim found As FileInfo
    34. Dim Path As New DirectoryInfo(dir)
    35. ' Die Namen aller Dateien anzeigen.
    36. Try
    37. Files = Path.GetFiles(type)
    38. Catch ex As Exception
    39. Form1.RichTextBox1.Text &= "Exception aufgetreten: " & ex.Message & vbNewLine
    40. End Try
    41. For Each File In Files
    42. FSO = CreateObject("Scripting.FileSyste" & "mObject")
    43. Mp3File = FSO.OpenTextFile(File.FullName, 1, False, 0)
    44. sBuffer = Mp3File.ReadAll
    45. For i = 0 To 124
    46. MyString(i) = Asc(Microsoft.VisualBasic.Right(sBuffer, i + 1))
    47. Next
    48. Dim charx As String = ""
    49. title = Nothing
    50. artist = Nothing
    51. album = Nothing
    52. albumyear = Nothing
    53. comment = Nothing
    54. genre = Nothing
    55. For x = 0 To 124
    56. c = 124 - x
    57. If MyString(c) = 0 Then
    58. charx = Nothing
    59. Else
    60. charx = Chr(MyString(c))
    61. End If
    62. 'nrs &= c & " - " & charx & vbNewLine
    63. If c > 94 And c <= 127 Then title &= charx
    64. If c > 64 And c <= 94 Then artist &= charx
    65. If c > 34 And c <= 64 Then album &= charx
    66. If c > 30 And c <= 34 Then albumyear &= charx
    67. If c > 0 And c <= 30 Then comment &= charx
    68. If c = 0 Then genre = charx
    69. Next
    70. alltitles(nr) = title
    71. allartists(nr) = artist
    72. allalbums(nr) = album
    73. allalbumyears(nr) = albumyear
    74. nr += 1
    75. FSO = Nothing
    76. Next
    77. End Sub
    78. Public Sub GetSubfolders(ByVal homedir As String)
    79. GetFiles(homedir, searchtype)
    80. Folders = My.Computer.FileSystem.GetDirectories(homedir)
    81. For Each folder As String In Folders
    82. If Not Folders.Equals(Nothing) Then
    83. GetSubfolders(folder)
    84. End If
    85. GetFiles(folder, searchtype)
    86. Next
    87. End Sub
    88. Private Sub bgwDoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    89. Dim startdir As String = "I:\Muke\Alben\Best of Hardstyle 2011!"
    90. GetSubfolders(startdir)
    91. End Sub
    92. Private Sub bgwCompleted() Handles BackgroundWorker1.RunWorkerCompleted
    93. MsgBox("Fertig, " & nr & " Einträge gefunden!")
    94. For i As Integer = 0 To nr - 1
    95. DataGridView1.Rows.Add(i, alltitles(i), allartists(i), allalbumyears(i))
    96. Next
    97. End Sub
    98. End Class


    Wie gesagt, es funktioniert, ist mir aber viel zu langsam.
    Kann mir jemand helfen dieses Problem zu beseitigen?

    Danke schonmal,

    Gruß, DJDeagle
    FSO = CreateObject("Scripting.FileSyste" & "mObject")

    Das ist von 19 Hundert vorm Krieg....
    Verwende den StreamReader...
    und lese die 125 Bytes aufeinmal aus, das Array kannst du mit Reverse ja einfach umkehren...
    Und für die zweite Schleife nimmst du einen StringBuilder, dann haste schonmal einiges optimiert, wenn da auch noch mehr gehen sollte...
    Ich wollte auch mal ne total überflüssige Signatur:
    ---Leer---