944,045 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 7914
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 17th, 2005
0

Text printing is giving me trouble

Expand Post »
ok, so i have been working on a program that i call "Sharppad" any ways it is a text editor. it has all teh basic functions. but it can also speak teh text you type. and convert text to .wav files. so you can listen to what you type. it also has a syntax editor. any ways i came too the part where i want it to print... and i get figure it out. i hvae tried code on the internet and it all just prints blank paper. any ideas?
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 18th, 2005
0

Re: Text printing is giving me trouble

dude, did you finish the mp3 copier?
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 18th, 2005
0

Re: Text printing is giving me trouble

lol, yea pretty much, i still cant get it to read all the tags. but it copies the mp3 from the ipod to the harddrive. it provides a skin for itunes,(looks like an ipod functions like one) provides an interface for making contacts to put on teh ipod(vcards). and is also an id3 editor. so yea thats done. still trying to get it to read all the tags


EDIT: Hey r0ck if i put the code on here do you think you could help me get it to read all the tags in the directory in display them in the listbox
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 18th, 2005
0

Re: Text printing is giving me trouble

o and r0ck one more question how could i let the user choose between mp4 and pm3 cuz i try to declarte the textbox as teh file type. but it wont work? maybe a whole new fileType(filetype2) or an if else statement?????
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 18th, 2005
0

Re: Text printing is giving me trouble

what about some radiobuttons which display the choice ? yes, you can post the code , so we can try to work it out
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 18th, 2005
0

Re: Text printing is giving me trouble

yea i was think bout radio buttons. but here is the weird thing. on my bro's ipod it read ALMOST all of them where as on mine and my dads it reads almost none....


i will post the code tommrow. its late now i gotta catch some z's


p.s

Thank you for all of your help. You have really taught me alot.
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 19th, 2005
0

Re: Text printing is giving me trouble

Quote originally posted by tayspen ...
yea i was think bout radio buttons. but here is the weird thing. on my bro's ipod it read ALMOST all of them where as on mine and my dads it reads almost none....


i will post the code tommrow. its late now i gotta catch some z's


p.s

Thank you for all of your help. You have really taught me alot.


Ok, here is teh code...Keep in mind i am trying to backup the songs off my ipod onto my harddrive. I got this down. but when it copies it comes out with the weird names like QEYX i want it to read the id3 tags as it copies and spits them out with good names. i also need to be able to coopy mp4's out to.( i think i can do that) what i reallly n eed help on is the id3 part. anywho here it is.


the first thing that i will do is press a browse button that will bring up a folerbrowser.....
C# Syntax (Toggle Plain Text)
  1.  
  2. folderBrowserDialog1.ShowDialog(); //the textbox2 text is = to the folderbrowser selected index
  3. textBox2.Text = folderBrowserDialog1.SelectedPath;


then it displays in the textbox, the filename.

From there its as easy as pressing the cop button..... this is the code for when it is pressed.....

C# Syntax (Toggle Plain Text)
  1.  
  2. private void button1_Click(object sender, EventArgs e)
  3. {
  4. try
  5. {
  6. string sourceDir = textBox1.Text + "\\iPod_Control\\Music";//add this to the drive that the user typed in (sets up the source file)
  7. string targetDir = folderBrowserDialog1.SelectedPath; //show them the browser there directory = target
  8.  
  9. foreach (string d in Directory.GetDirectories(sourceDir))
  10. {
  11.  
  12. foreach (string f in Directory.GetFiles(d, fileType))
  13. {
  14.  
  15.  
  16. MessageBox.Show("Please be patient process may take a while", "Please wait");//Notify the user
  17. label2.Visible = true;//label2 now visible upon button click
  18.  
  19.  
  20. File.Copy(f,
  21. targetDir + "\\" + new FileInfo(f).Name, //Attempt copy
  22. false);
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30. }
  31. }

Here is teh Read(); part. i tried puting Read(); in a few places. (no dice)

C# Syntax (Toggle Plain Text)
  1.  
  2. public void Read()
  3. {
  4.  
  5. // Read the 128 byte ID3 tag into a byte array
  6. FileStream oFileStream;
  7. oFileStream = new FileStream(this.filename, FileMode.Open);
  8. byte[] bBuffer = new byte[128];
  9. oFileStream.Seek(-128, SeekOrigin.End);
  10. oFileStream.Read(bBuffer, 0, 128);
  11. oFileStream.Close();
  12.  
  13. // Convert the Byte Array to a String
  14. Encoding instEncoding = new ASCIIEncoding(); // NB: Encoding is an Abstract class
  15. string id3Tag = instEncoding.GetString(bBuffer);
  16.  
  17. // If there is an attched ID3 v1.x TAG then read it
  18. if (id3Tag.Substring(0, 3) == "TAG")
  19. {
  20. this.Title = id3Tag.Substring(3, 30).Trim();
  21. this.Artist = id3Tag.Substring(33, 30).Trim();
  22. this.Album = id3Tag.Substring(63, 30).Trim();
  23. this.Year = id3Tag.Substring(93, 4).Trim();
  24. this.Comment = id3Tag.Substring(97, 28).Trim();
  25.  
  26. // Get the track number if TAG conforms to ID3 v1.1
  27. if (id3Tag[125] == 0)
  28. this.Track = bBuffer[126];
  29. else
  30. this.Track = 0;
  31. this.GenreID = bBuffer[127];
  32.  
  33. this.hasTag = true;
  34. // ********* IF USED IN ANGER: ENSURE to test for non-numeric year
  35. }
  36. else
  37. {
  38. this.hasTag = false;
  39. }
  40. }

(i might have trimmed some out so if u see somthing missing lemme no)


maybe i should update teh mp3's as there being cbacked up

C# Syntax (Toggle Plain Text)
  1.  
  2. public void updateMP3Tag()
  3. {
  4. // Trim any whitespace
  5. this.Title = this.Title.Trim();
  6. this.Artist = this.Artist.Trim();
  7. this.Album = this.Album.Trim();
  8. this.Year = this.Year.Trim();
  9. this.Comment = this.Comment.Trim();
  10.  
  11. // Ensure all properties are correct size
  12. if (this.Title.Length > 30) this.Title = this.Title.Substring(0, 30);
  13. if (this.Artist.Length > 30) this.Artist = this.Artist.Substring(0, 30);
  14. if (this.Album.Length > 30) this.Album = this.Album.Substring(0, 30);
  15. if (this.Year.Length > 4) this.Year = this.Year.Substring(0, 4);
  16. if (this.Comment.Length > 28) this.Comment = this.Comment.Substring(0, 28);
  17.  
  18. // Build a new ID3 Tag (128 Bytes)
  19. byte[] tagByteArray = new byte[128];
  20. for (int i = 0; i < tagByteArray.Length; i++) tagByteArray[i] = 0; // Initialise array to nulls
  21.  
  22. // Convert the Byte Array to a String
  23. 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
  24. // Copy "TAG" to Array
  25. byte[] workingByteArray = instEncoding.GetBytes("TAG");
  26. Array.Copy(workingByteArray, 0, tagByteArray, 0, workingByteArray.Length);
  27. // Copy Title to Array
  28. workingByteArray = instEncoding.GetBytes(this.Title);
  29. Array.Copy(workingByteArray, 0, tagByteArray, 3, workingByteArray.Length);
  30. // Copy Artist to Array
  31. workingByteArray = instEncoding.GetBytes(this.Artist);
  32. Array.Copy(workingByteArray, 0, tagByteArray, 33, workingByteArray.Length);
  33. // Copy Album to Array
  34. workingByteArray = instEncoding.GetBytes(this.Album);
  35. Array.Copy(workingByteArray, 0, tagByteArray, 63, workingByteArray.Length);
  36. // Copy Year to Array
  37. workingByteArray = instEncoding.GetBytes(this.Year);
  38. Array.Copy(workingByteArray, 0, tagByteArray, 93, workingByteArray.Length);
  39. // Copy Comment to Array
  40. workingByteArray = instEncoding.GetBytes(this.Comment);
  41. Array.Copy(workingByteArray, 0, tagByteArray, 97, workingByteArray.Length);
  42. // Copy Track and Genre to Array
  43. tagByteArray[126] = System.Convert.ToByte(this.Track);
  44. tagByteArray[127] = System.Convert.ToByte(this.GenreID);
  45.  
  46. // SAVE TO DISK: Replace the final 128 Bytes with our new ID3 tag
  47. FileStream oFileStream = new FileStream(this.filename, FileMode.Open);
  48. if (this.hasTag)
  49. oFileStream.Seek(-128, SeekOrigin.End);
  50. else
  51. oFileStream.Seek(0, SeekOrigin.End);
  52. oFileStream.Write(tagByteArray, 0, 128);
  53. oFileStream.Close();
  54. this.hasTag = true;
  55. }

So that bout some that up. thanks r0ck for any ideas that you might have


p.s

i have tried the previous ideas(i just may have switched some things around or put it back hw it was,, so if it looks like i havnt tried any of your previous ideas...i have)
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 19th, 2005
0

Re: Text printing is giving me trouble

Hi, i think yo didn't get the point of the Read() function ...Read is in fact a member function of a class called ID3v1.

I gave a you a link to a this complete class in another thread, so what you do is the following, copy-paste the whole code to a file called ID3v1.cs , and then you incorporate that file into your project, then after that you call it like this:

C# Syntax (Toggle Plain Text)
  1. foreach (string f in Directory.GetFiles(d, fileType))
  2. {
  3. MessageBox.Show("Please be patient process may take a while", "Please wait");//Notify the user
  4. label2.Visible = true;//label2 now visible upon button click
  5.  
  6. // Now try to read tags from the file to copy
  7. ID3v1 mp3Tag = new ID3v1(f);
  8. File.Copy(f, targetDir+"\\"+mp3Tag.Artist+"_"+mp3Tag.Title+new FileInfo(f).Extension, false);
  9.  
  10. //........
  11. }

I didn't test this code, so there might be some bugs.
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Sep 19th, 2005
0

Re: Text printing is giving me trouble

Quote originally posted by r0ckbaer ...
Hi, i think yo didn't get the point of the Read() function ...Read is in fact a member function of a class called ID3v1.

I gave a you a link to a this complete class in another thread, so what you do is the following, copy-paste the whole code to a file called ID3v1.cs , and then you incorporate that file into your project, then after that you call it like this:

C# Syntax (Toggle Plain Text)
  1. foreach (string f in Directory.GetFiles(d, fileType))
  2. {
  3. MessageBox.Show("Please be patient process may take a while", "Please wait");//Notify the user
  4. label2.Visible = true;//label2 now visible upon button click
  5.  
  6. // Now try to read tags from the file to copy
  7. ID3v1 mp3Tag = new ID3v1(f);
  8. File.Copy(f, targetDir+"\\"+mp3Tag.Artist+"_"+mp3Tag.Title+new FileInfo(f).Extension, false);
  9.  
  10. //........
  11. }

I didn't test this code, so there might be some bugs.
lemme gixe it a go..... be back soon
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Sep 19th, 2005
0

Re: Text printing is giving me trouble

ok so i tried this is is the exact code under the rip button


C# Syntax (Toggle Plain Text)
  1.  
  2.  
  3. private void button1_Click(object sender, EventArgs e)
  4. {
  5.  
  6. try
  7. {
  8.  
  9. string sourceDir = textBox1.Text + "\\iPod_Control\\Music";//add this to the drive that the user typed in (sets up the source file)
  10. string targetDir = folderBrowserDialog1.SelectedPath; //show them the browser there directory = target
  11.  
  12. foreach (string d in Directory.GetDirectories(sourceDir))
  13. {
  14.  
  15.  
  16. foreach (string f in Directory.GetFiles(d, fileType))
  17. {
  18.  
  19. label2.Visible = true;//label2 now visible upon button click
  20.  
  21. // Now try to read tags from the file to copy
  22. ID3v1 mp3Tag = new ID3v1(f);
  23. File.Copy(f, targetDir + "\\" + mp3Tag.Artist + "_" + mp3Tag.Title + new FileInfo(f).Extension, false);
  24.  
  25. //........
  26. }
  27. }
  28. }
  29.  
  30. catch
  31. {
  32. frmerror frm = new frmerror();
  33. frm.ShowDialog(this); // show notes (EDIT: notes canceled now show about)
  34. frm.Dispose();
  35. }
  36.  
  37.  
  38.  
  39.  
  40. }




EDIT: just took off catch statement. the error was that the file - already exists...
now it copies one song with the file name -

and then it shows me my catch form if somthing goes wrong.....

i hadded that ID# form and everything...
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Help with timer..
Next Thread in C# Forum Timeline: how do i update to Access db?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC