ID3v1 - Coding Problems...

npsnet

Newcomer
Joined
Jun 8, 2003
Messages
4
Location
Pennsylvania
I've been pondering for over an hour now about why the following coding will not work. The coding is as logical as it could be, what's the problem?

Imports System.io
Public Class frmID3Tool
Inherits System.Windows.Forms.Form

+ Windows Form Designer generated code

Private Sub tlbToolbar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
Handles tlbToolbar.ButtonClick

If e.Button Is tlbToolbar.Buttons(0) Then
If dlgOpen.ShowDialog() <> DialogResult.Cancel Then
Dim filepath As String = dlgOpen.FileName

Dim fs As FileStream = New FileStream(filepath,FileMode.Open)

Dim id3title(30) As Byte

fs.Seek(125, SeekOrigin.End)
fs.Read(id3title, 0, 30)

txtTitle.Text = System.Text.Encoding.ASCII.GetString(id3title)
End If
End If
End Sub
End Class

Also, why do I have to declare my variables as bytes and not strings like I'd prefer? Why have to convert it to a string when it could've been a string since it was intialized?

Thanks for your help,
npsnet
 
Minor Correction to Original Coding

*Minor correction to the coding -npsnet

Imports System.io
Public Class frmID3Tool
Inherits System.Windows.Forms.Form

+ Windows Form Designer generated code

Private Sub tlbToolbar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
Handles tlbToolbar.ButtonClick

If e.Button Is tlbToolbar.Buttons(0) Then
If dlgOpen.ShowDialog() <> DialogResult.Cancel Then
Dim filepath As String = dlgOpen.FileName

Dim fs As FileStream = New FileStream(filepath,FileMode.Open)

Dim id3title(30) As Byte

fs.Seek(-125, SeekOrigin.End)
fs.Read(id3title, 0, 30)

txtTitle.Text = System.Text.Encoding.ASCII.GetString(id3title)
End If
End If
End Sub
End Class
 
npsnet, what are you trying to do??? open what kind of file??? trying to read a tag of a MP3 file??? if so, I have some code that can help you out with this task
 
ID3v1.1 Tag Editor

I made a ID3v1.1 tag editor in VB6 awhile so I figured I update the code to vb.net. I have the whole concept down and know what i need to do but I'm having trouble with byte arrays I think.
The VB6 version used strings and had no troubles whatsoever.

To be efficint when reading an ID3 tag you should first check to see if there is tag. Why declare all kinds of variables and such when there might not even be a tag. If there is a tag, then the mp3 will be marked TAG 128 bytes from the end of file with rest of the tag following.

Assume that you've opened the file and stored whatever those three bytes in the file could be, in a byte array named tag(3). If the mp3 had no tag then the byte array is empty. If there was tag then the byte array is a decimal number representing the word TAG because that's what you trying to read out of the file.

A bunch of numbers doesn't mean much so you convert the byte array to a string, so 846571 is now ASCII converted TAG.

' Convert the byte array to a string
' str now equals TAG not 846571
dim str as string = system.text.encoding.ascii.getstring(tag)

***** HERE IS THE KILLER *****
If I send str to a textbox or msgbox the value of str displays TAG which it should. When you test it without a textbox or msgbox nothing gets confirmed.

Example:

If str = "TAG" then
msgbox("ID3 tag found.")
end if

For some reason when I use this statement it does nothing, which means that str isn't equal to TAG, although just before it displayed TAG in a textbox or msgbox. Why is this?

Thanks for all your help,

-npsnet
 
Last edited:
I don't suppose you would be willing to share your solution?
I am having the same problem -

Instead of returning TAG, it is returning "TAG
I can get rid of the quote on TAG, but not the other fields. Thanks...
 
Back
Top