Sub Class_Globals
Private fx As JFX
Dim Fi As JavaObject
Dim audioFile As JavaObject
' Dim audioHeader As JavaObject
Dim TagSet As JavaObject
Dim Fi As JavaObject
Dim audioTaggerFileIO As JavaObject
Dim mSourceFolder As String
Dim mapTags As Map
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Folder As String)
setSourceFolder(Folder)
Fill_TagMap
End Sub
' Change this property if the SourceFolder changes
Public Sub setSourceFolder (sVar As String)
mSourceFolder = sVar
End Sub
Sub Fill_TagMap
' Initialize the Tags map and enter known tags with empty values
mapTags.Initialize
mapTags.Put("ALBUM", "")
mapTags.Put("ARTIST", "")
mapTags.Put("GENRE", "")
mapTags.Put("DATE", "")
mapTags.Put("YEAR", "")
mapTags.Put("DISCNUMBER", "")
mapTags.Put("TOTALDISCS", "")
mapTags.Put("TOTALTRACKS", "")
mapTags.Put("ALBUM", "")
mapTags.Put("TRACKNUMBER", "")
mapTags.Put("TITLE", "")
' May not exist
mapTags.Put("ALBUM_ARTIST", "")
mapTags.Put("COMPOSER", "")
mapTags.Put("CONDUCTOR", "")
mapTags.Put("ORCHESTRA", "")
mapTags.Put("SOLOISTS", "")
mapTags.Put("COMMENT", "")
End Sub
' Run this to set up each new track file
Public Sub Set_TagSet (FileName As String) As ResumableSub
Dim TagIsSet As Boolean
Try
' get an instance of AudioFileIO so we can read the file
audioTaggerFileIO.InitializeNewInstance("org.jaudiotagger.audio.AudioFileIO",Null)
' Check that the file (Folder, Name) exists:
If File.Exists(mSourceFolder, FileName) Then
' file to read must be a java.io.File just pass full path to it
Fi.InitializeNewInstance("java.io.File",Array(File.Combine(mSourceFolder, FileName)))
audioFile = audioTaggerFileIO.RunMethod("read", Array(Fi))
' read the headers from audioFile and put into audioHeaders
' again audioHeaders will assume the correct class as it's a java object
' audioHeader = audioFile.RunMethod("getAudioHeader",Null)
' read the tags from the audioFile
TagSet = audioFile.RunMethod("getTag",Null)
TagIsSet = True
Else
fx.Msgbox2(Null, $"File ${FileName} not found."$, "TagSet Error", _
"", "OK", "", fx.MSGBOX_ERROR)
End If
Catch
Log($"Exception Message: ${LastException.Message}"$)
End Try
Log(TagSet)
Return TagIsSet
End Sub
Public Sub Map_Tag (Key As String) As ResumableSub
Try
Dim HasField As Boolean
Dim TagValue As String
HasField = TagSet.RunMethod("hasField", Array(Key))
Log($"HasField ${Key} is ${HasField}"$)
If HasField Then
TagValue = TagSet.runmethod("getFirst", Array(Key))
TagValue = TagValue.Trim
Else
TagValue = ""
End If
Catch
Log(LastException.Message)
TagValue = Null
End Try
Return TagValue
End Sub
'
Public Sub Map_AllTags As ResumableSub
For Each s As String In mapTags.Keys
Wait for (Map_Tag (s)) complete (TagValue As String)
mapTags.Put(s, TagValue)
Next
Return mapTags
End Sub