W
wk
Hi,
I am reading a mp3 file's last 128 bytes and putting the text into
string variables.
What is happening is that the string is being stored with, probably
some wrong encoding or character, and hence has a " in front, and i
cant see the full string in VB 2005 express's debug mode. I have based
this off an example from the web.
I have spent a full day trying to debug this with a lot of different
ways, and now am exausted with ideas.
try giving the code any mp3 file on your disk, and then debug at line
75 of class1.vb to see the value of 'Title' variable.
Here is the code. When u run it, becuase of the problem said above, u
wont see the "<" in the messagebox
uage from form1.vb
----------------------------------
Dim mp3 As New ID3v1()
mp3.filename = "c:\temp\GarajBarasSawanGhirAayo-junoon.mp3"
mp3.filename = "c:\temp\BullaKiJana.mp3"
mp3.Read()
MsgBox(mp3.Artist.Trim & "<")
class1.vb
-----------------
Imports System
Imports System.IO
Imports System.Text
'/ <summary>
'/ Reads/writes Id3v1 tags. lots of help from Paul Lockwood's code
'/ http:'www.csharphelp.com/archives/archive226.html
'/ </summary>
Public Class ID3v1
Public filename As String
Public Title As String
Public Artist As String
Public Album As String
Public Year As String
Public Comment As String
Public GenreID As Integer
Public Track As Integer
Public hasTag As Boolean
Private Sub Initialize_Components()
hasTag = False
filename = ""
Title = ""
Artist = ""
Album = ""
Year = ""
Comment = ""
GenreID = 0
Track = 0
End Sub
Public Sub ID3v1()
Initialize_Components()
End Sub
Public Sub ID3v1(ByVal fname As String)
Initialize_Components()
filename = fname
End Sub
Public Sub Read()
' Read the 128 byte ID3 tag into a byte array
Dim oFileStream As FileStream = New FileStream(filename,
FileMode.Open)
'oFileStream = New FileStream(filename, FileMode.Open)
'byte[] bBuffer = new byte[128]
Dim bBuffer(128) As Byte
oFileStream.Seek(-128, SeekOrigin.End)
oFileStream.Read(bBuffer, 0, 128)
oFileStream.Close()
' Convert the Byte Array to a String
'Encoding(instEncoding = New ASCIIEncoding()) ' NB: Encoding
is an Abstract class
Dim instEncoding As Encoding = Encoding.ASCII
Dim id3Tag As String = instEncoding.GetString(bBuffer)
' If there is an attched ID3 v1.x TAG then read it
If (id3Tag.Substring(0, 3) = "TAG") Then
Title = id3Tag.Substring(3, 30).Trim()
Artist = id3Tag.Substring(33, 30).Trim()
Album = id3Tag.Substring(63, 30).Trim()
Year = id3Tag.Substring(93, 4).Trim()
Comment = id3Tag.Substring(97, 28).Trim()
' Get the track number if TAG conforms to ID3 v1.1
If (id3Tag(125) = "") Then
Track = bBuffer(126)
Else
Track = 0
End If
GenreID = bBuffer(127)
hasTag = True
Else
hasTag = False
End If
End Sub
End Class
I am reading a mp3 file's last 128 bytes and putting the text into
string variables.
What is happening is that the string is being stored with, probably
some wrong encoding or character, and hence has a " in front, and i
cant see the full string in VB 2005 express's debug mode. I have based
this off an example from the web.
I have spent a full day trying to debug this with a lot of different
ways, and now am exausted with ideas.
try giving the code any mp3 file on your disk, and then debug at line
75 of class1.vb to see the value of 'Title' variable.
Here is the code. When u run it, becuase of the problem said above, u
wont see the "<" in the messagebox
uage from form1.vb
----------------------------------
Dim mp3 As New ID3v1()
mp3.filename = "c:\temp\GarajBarasSawanGhirAayo-junoon.mp3"
mp3.filename = "c:\temp\BullaKiJana.mp3"
mp3.Read()
MsgBox(mp3.Artist.Trim & "<")
class1.vb
-----------------
Imports System
Imports System.IO
Imports System.Text
'/ <summary>
'/ Reads/writes Id3v1 tags. lots of help from Paul Lockwood's code
'/ http:'www.csharphelp.com/archives/archive226.html
'/ </summary>
Public Class ID3v1
Public filename As String
Public Title As String
Public Artist As String
Public Album As String
Public Year As String
Public Comment As String
Public GenreID As Integer
Public Track As Integer
Public hasTag As Boolean
Private Sub Initialize_Components()
hasTag = False
filename = ""
Title = ""
Artist = ""
Album = ""
Year = ""
Comment = ""
GenreID = 0
Track = 0
End Sub
Public Sub ID3v1()
Initialize_Components()
End Sub
Public Sub ID3v1(ByVal fname As String)
Initialize_Components()
filename = fname
End Sub
Public Sub Read()
' Read the 128 byte ID3 tag into a byte array
Dim oFileStream As FileStream = New FileStream(filename,
FileMode.Open)
'oFileStream = New FileStream(filename, FileMode.Open)
'byte[] bBuffer = new byte[128]
Dim bBuffer(128) As Byte
oFileStream.Seek(-128, SeekOrigin.End)
oFileStream.Read(bBuffer, 0, 128)
oFileStream.Close()
' Convert the Byte Array to a String
'Encoding(instEncoding = New ASCIIEncoding()) ' NB: Encoding
is an Abstract class
Dim instEncoding As Encoding = Encoding.ASCII
Dim id3Tag As String = instEncoding.GetString(bBuffer)
' If there is an attched ID3 v1.x TAG then read it
If (id3Tag.Substring(0, 3) = "TAG") Then
Title = id3Tag.Substring(3, 30).Trim()
Artist = id3Tag.Substring(33, 30).Trim()
Album = id3Tag.Substring(63, 30).Trim()
Year = id3Tag.Substring(93, 4).Trim()
Comment = id3Tag.Substring(97, 28).Trim()
' Get the track number if TAG conforms to ID3 v1.1
If (id3Tag(125) = "") Then
Track = bBuffer(126)
Else
Track = 0
End If
GenreID = bBuffer(127)
hasTag = True
Else
hasTag = False
End If
End Sub
End Class