Topic: Visual C# pack() function
Hey guys,
I'm looking for a pack() function in C#, similar to PHP's pack() function.
Would be handy if it existed...
Thanks alot,
-- Bekko
You are not logged in. Please login or register.
PunBB Forums → Programming → Visual C# pack() function
Hey guys,
I'm looking for a pack() function in C#, similar to PHP's pack() function.
Would be handy if it existed...
Thanks alot,
-- Bekko
there's no pack equiv. you'll have to serialize it by hand that way. If I get a few minutes I'll see if I can cook something up.
Have a look at System.Runtime.Serialization and System.Runtime.Serialization.Formatters.Binary.BinaryFormatter in particular.
It is a whole different way of thinking than with PHP's pack() as C# is OO and each object is responsible for its own serialization.
Hrmm, thanks, but since I'm trying to port an ID3 reader from PHP to C#, it's kinda hard to go from pack() to the BinaryFormatter =P
But if you can point me in the right direction for an ID3 reader...
if you know what is where, the FileStream class lets you read byte by byte from the file.
using ( Stream mp3 = File.OpenRead("song.mp3") ) {
byte[] buffer = new byte[4096];
s.Read(buffer, 0, buffer.Length);
// you can also read specific areas:
buffer = new byte[128];
int start = 4097;
int lengthToRead = buffer.Length;
s.Read(buffer, start, lengthToRead);
}
there's already id3 readers/ writers out there in C#, and if you didnt want to use them, then they should help you out with where to read / write. http://sourceforge.net/projects/csid3lib/
If that library works with .NET, I'll definately try it out Thanks!
yea its all in C#
This is probably a n00bish error, but the library refuses to read the ID3v1 tag (and yes, it's there, I checked with Winamp).
Here's my code:
/* Initialise tagreader */
ID3v1 tagreader = new ID3v1();
/* Open file stream */
StreamReader file = new StreamReader("C:/Documents and Settings/El Bekko/My Documents/My Music/AC-DC/Stiff Upper Lip/09 Damned.mp3");
/* Get ID3v1 info from file. */
try
{
tagreader.Deserialize(file.BaseStream);
textBox2.Text += "\r\nID3 Information: \r\nArtist: " + tagreader.Artist + "\r\n";
}
catch
{
textBox2.Text += "No ID3v1 Information found in file.\r\n";
}
looks like you should use tagmanager to deserialize the mp3.
ID3v1 id3 = new ID3v1();
using ( Stream s = File.OpenRead(@"\\dc01\DUMP\MP3\Tool\Opiate\Tool - Opiate - 01 - sweat.mp3") ) {
TagManager mgr = new TagManager();
id3.TagModel = mgr.Deserialize(s);
}
artistTextBox.Text = id3.Artist;
// ...
Hey, thanks
Here's the result of your help:
http://icstrategy.midgetforhire.com/Tools/ID3Lister.zip
Note, I just zipped up the 'publish' directory
very cool!
I've never tried to use the click once publishing (dont trust it personally), but it ran pretty good.
I agree with MadHatter, cool app!
Thanks
Reminds me of a small C app I wrote in 2000. It inserted ID3 tags by "guessing" the title, artist, tracknumber and so on via the file and folder name
PunBB Forums → Programming → Visual C# pack() function
Powered by PunBB, supported by Informer Technologies, Inc.