|
-
Oct 7th, 2006, 10:46 AM
#1
Thread Starter
New Member
How do I put everything togather to work?
Hi my name is Sim.
And I would like to ask u a question.
I code in C# not so long and have basic understanding of it but I still do not get yet how to put things togather. For example, I would like to create my own id3 tag editor in C# with help of C# id3 library. That library is a dll file and now my question is how do I use it? How do I connect it to my own form and make my own bottons with functionality of that dll to be able to read and write id3 tags?
Below is another example, of a class what I do not have understanding how to connect it to my own windows form.
So I basicly need information on how to put everything to work altogather. I also want to use sourcecode found on many site with my own programms but how do I put it al togather.
Thanks a lot and I hope somebody will come with an answer.
using System;
using System.IO;
using System.Text;
namespace mp3info
{
public class ID3v1
{
public string filename;
public string Title;
public string Artist;
public string Album;
public string Year;
public string Comment;
public int GenreID;
public int Track;
public bool hasTag;
private void Initialize_Components()
{
hasTag = false;
filename = "";
Title = "";
Artist = "";
Album = "";
Year = "";
Comment = "";
GenreID = 0;
Track = 0;
}
public ID3v1()
{
Initialize_Components();
}
public ID3v1( string filename )
{
Initialize_Components();
this.filename = filename;
}
public void Read ()
{
// Read the 128 byte ID3 tag into a byte array
FileStream oFileStream;
oFileStream = new FileStream( this.filename, FileMode.Open);
byte[] bBuffer = new byte[128];
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
string id3Tag = instEncoding.GetString(bBuffer);
// If there is an attched ID3 v1.x TAG then read it
if (id3Tag .Substring(0,3) == "TAG")
{
this.Title = id3Tag.Substring( 3, 30).Trim();
this.Artist = id3Tag.Substring( 33, 30).Trim();
this.Album = id3Tag.Substring( 63, 30).Trim();
this.Year = id3Tag.Substring( 93, 4).Trim();
this.Comment = id3Tag.Substring( 97,28).Trim();
// Get the track number if TAG conforms to ID3 v1.1
if (id3Tag[125]==0)
this.Track = bBuffer[126];
else
this.Track = 0;
this.GenreID = bBuffer[127];
this.hasTag = true;
// ********* IF USED IN ANGER: ENSURE to test for non-numeric year
}
else
{
this.hasTag = false;
}
}
public void updateMP3Tag ()
{
// Trim any whitespace
this.Title = this.Title.Trim();
this.Artist = this.Artist.Trim();
this.Album = this.Album.Trim();
this.Year = this.Year.Trim();
this.Comment = this.Comment.Trim();
// Ensure all properties are correct size
if (this.Title.Length > 30) this.Title = this.Title.Substring(0,30);
if (this.Artist.Length > 30) this.Artist = this.Artist.Substring(0,30);
if (this.Album.Length > 30) this.Album = this.Album.Substring(0,30);
if (this.Year.Length > 4) this.Year = this.Year.Substring(0,4);
if (this.Comment.Length > 28) this.Comment = this.Comment.Substring(0,28);
// Build a new ID3 Tag (128 Bytes)
byte[] tagByteArray = new byte[128];
for ( int i = 0; i < tagByteArray.Length; i++ ) tagByteArray[i] = 0; // Initialise array to nulls
// Convert the Byte Array to a String
Encoding instEncoding = new ASCIIEncoding(); // NB: Encoding is an Abstract class // ************ To DO: Make a shared instance of ASCIIEncoding so we don't keep creating/destroying it
// Copy "TAG" to Array
byte[] workingByteArray = instEncoding.GetBytes("TAG");
Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);
// Copy Title to Array
workingByteArray = instEncoding.GetBytes(this.Title);
Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);
// Copy Artist to Array
workingByteArray = instEncoding.GetBytes(this.Artist);
Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);
// Copy Album to Array
workingByteArray = instEncoding.GetBytes(this.Album);
Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);
// Copy Year to Array
workingByteArray = instEncoding.GetBytes(this.Year);
Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);
// Copy Comment to Array
workingByteArray = instEncoding.GetBytes(this.Comment);
Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);
// Copy Track and Genre to Array
tagByteArray[126] = System.Convert.ToByte(this.Track);
tagByteArray[127] = System.Convert.ToByte(this.GenreID);
// SAVE TO DISK: Replace the final 128 Bytes with our new ID3 tag
FileStream oFileStream = new FileStream(this.filename , FileMode.Open);
if (this.hasTag)
oFileStream.Seek(-128, SeekOrigin.End);
else
oFileStream.Seek(0, SeekOrigin.End);
oFileStream.Write(tagByteArray,0, 128);
oFileStream.Close();
this.hasTag = true;
}
}
}
-
Oct 7th, 2006, 05:33 PM
#2
Re: How do I put everything togather to work?
Whether it is a part of the .NET Framework or not, you have to add a reference to a library, i.e. DLL, to your project to be able to use the types it contains. Go to the Solution Explorer, right-click your project and select Add Reference. Navigate to the library you want to use and select it. Your project now has access to all the types that that library contains.
If you have a code file rather than a compiled DLL, you can add that to your project directly by selecting Add Existing Item. This will add the class to your project as though you wrote it yourself.
-
Oct 21st, 2006, 11:06 PM
#3
Thread Starter
New Member
Re: How do I put everything togather to work?
Thanks a lot. I will try to figure it further out how to use that dll or class in my project.
Ok it is so that I understand what you are saying and it definetelly helps me further. Only it is due to the nature of programming so that you have to know exactly what code pieces you want to write.
And of course I can find it myself out what exactly I have to write in many of those books that I have but I also know out of my experience that I won't find exactly commands for my case and will have to brake down my head figuring out how I have to adjust existing examples for my case.
So if this wil give no further result I wil also have to do that what I just told BUT
if it is for you like english langauge C# syntax then I would like to ask you for another couple of minutes and write for me down how I would have to connect button browse with Read method that returns tag info and how I would have to code further to use that info in a text box. Als how I create an instance of a class.
I am asking pretty much I have feeling but anyway whatever you might reply if at all I hope that if that demands not too much of your time that you will write for me down what code I have to use.
It is actually the first time that I go this way in finding solution for my problem and think that it maybe way much easier if someone who speaks C# just as I do english wil find it not too difficult to write some code for me and of course other.
Thanks a lot again. I wish I could do something for you.
Last edited by sim-the-noone; Oct 21st, 2006 at 11:31 PM.
Reason: To add somethings which come in me up later
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|