Public Sub ReadMP3File(FilePath As String, FileName As String) As ResumableSub
Dim MediaPlayer As MediaPlayer
Dim TrackInfo As TTrackInfo
TrackInfo.Initialize
TrackInfo.IsValid = True
If FilePath.CharAt(FilePath.Length-1) <> "\" Then FilePath = FilePath &"\"
TrackInfo.FilePath = FilePath
TrackInfo.FileName = FileName
If File.Exists(FilePath, FileName) = False Then
TrackInfo.FileExists = False
Return TrackInfo
End If
TrackInfo.FileExists = True
MediaPlayer.Initialize("", File.GetUri(FilePath, FileName))
Sleep(0) ' Need this Sleep so the MediaPlayer will actually load the track and have the info available
Dim jo_mp As JavaObject = MediaPlayer 'not sure where it comes from
Dim metadata As JavaObject = jo_mp.RunMethodJO("getMedia", Null).RunMethod("getMetadata", Null)
'--------------------------------------------------------------------------------------------------------------------------
' See if we can read the Media info using MetaData - If not try and use what we have in the Database
'--------------------------------------------------------------------------------------------------------------------------
TrackInfo.Album = metadata.RunMethod("get", Array("album"))
TrackInfo.Album = TrackInfo.Album.Trim
TrackInfo.Artist = metadata.RunMethod("get", Array("artist"))
TrackInfo.Artist = TrackInfo.Artist.Trim
TrackInfo.Song = metadata.RunMethod("get", Array("title"))
TrackInfo.Song = TrackInfo.Song.Trim
TrackInfo.Number = metadata.RunMethod("get", Array("track"))
TrackInfo.Number = TrackInfo.Number.Trim
TrackInfo.Year = metadata.RunMethod("get", Array("year"))
TrackInfo.Year = TrackInfo.Year.Trim
Dim Duration As String = metadata.RunMethod("get", Array("duration"))
Duration = Duration.Trim
If Duration.Length > 0 Then
Dim Space As Int = Duration.LastIndexOf(" ms")
If Space <> -1 Then
Duration = Duration.SubString2(0, Space)
End If
End If
If IsNumber(Duration) = False Then
Duration = 0
Else
Duration = Duration / 1000
End If
TrackInfo.Duration = Duration
TrackInfo.CoverArt = metadata.RunMethod("get", Array("image"))
If IsNumber(TrackInfo.Number) = False Or TrackInfo.Number = 0 Then
Dim TrackOffset As Int = TrackInfo.FileName.IndexOf(" - ")
If TrackOffset <> -1 Then
Dim Track As String = TrackInfo.FileName.SubString2(0, TrackOffset)
Track = Track.Trim
If IsNumber(Track) Then TrackInfo.Number = Track
End If
End If
Return TrackInfo
End Sub