Click here to Skip to main content
Click here to Skip to main content
Go to top

Easy MP3 Recording (also using iTunes)

, 28 Aug 2010
Rate this:
Please Sign up or sign in to vote.
Class library and working program allowing you to easily record MP3, wav and raw pcm files. Can also integrate with iTunes.

Introduction

A year ago, my sister and I wanted to make Mp3 back-up copies of everything we had bought on iTunes. So I wrote this program and posted an article on it. However, the program itself was complicated to use and cumbersome in its code as I never bothered to clean up the code once I had finished programming. However, recently it became necessary for me to produce an easy-to-use version. So, while I was improving the design of the application, I thought I'd improve the code as well. As a result, I have produced a library with three useful classes in it (and some helper classes used internally). The two classes are Recorder and iTunes Recorder Extension. Recorder is the base recording class that uses the Istrib libraries (available from here) to record stuff. This can easily be incorporated into any application that wishes to record stuff. iTunes Recorder Extension is more specific as the name suggests. This class provides an easily used object that links iTunes and its libraries with the Recorder class and Istrib libraries.

Using the Code

To use my code is very simple. You need simply to create a Recorder object or iTunesRecorderExtension object. Then setup a few objects and call one of the Start functions.

For this article, I will deal with the iTunesRecorderExtension object as that is what is used in my application though the Recorder class is available and just as easy to use.

To create an iTunesRecorderExtension object, simply do the following:

iTunesRecorderExtension TheRecorder = new iTunesRecorderExtension(true, "A Folder Path");

There are two parameters:

  • DoUseLog - bool
  • ALogFolderPath - string

DoUseLog should be true if you wish to use my Log class. A Log object is a simple way of reading and writing from a text file but in a log format. When you tell the log to write an entry, it automatically adds the long date and time and splits records up so it can be easily read. If you want to use a log, you must also pass it a Log Folder Path. This is a string containing the path to the folder you wish the log to be stored in. For the iTunesRecorderExtension, there are two logs; the Recorder log which comes from the underlying Recorder object and the Application log which comes from the iTunesRecorderExtension and stores information. The Recorder log records when recording starts of each track and what track it was. Also, any errors that the Recorder object encounters are logged. The Application log records when overall recording starts and finishes and also any errors the Recorder object passes back and its own errors.

To use the class, you must do three things:

  1. Select the SoundCaptureDevice
  2. Give it a folder name to store the recorded track in
  3. Tell it to record

To select a sound capture device, you should use a combo box on screen as working out which device has got sound playing on it and which are simply other unused sound cards, etc. is not supported.

The following code adds the available devices to a combo box and could be put in a load function at the start of the application:

List<object> Objects = new List<object>(); 
for (int i = 0; i < TheRecorder.AvailableDevices.Count; i++) 
{ 
	Objects.Add(TheRecorder.AvailableDevices[i]);
} 
SoundCaptureDevicesCmb.Items.AddRange(Objects.ToArray());

The following code transfers the users' selected device to the iTunesRecorderExtension object:

TheRecorder.Device = (Istrib.Sound.SoundCaptureDevice)
	(SoundCaptureDevicesCmb.Items[SoundCaptureDevicesCmb.SelectedIndex]);

To tell the iTunesRecorderExtension object where to save the recorded track, you need one line of code:

TheRecorder.OutputFolder = OutputFolderBox.Text;

The file name is worked out automatically. The files are also sorted by subfolders. The top layer is the Artist, the next subfolder is the Album and in that the track is stored. (Note: If the Artist and or Album is blank/null, they are set to the text 'Blank'!)

Finally you must tell the iTunesRecorderExtension to record. This can be done in two ways, one records immediately and one waits till a designated time to start recording and another time to stop recording. The second way I developed because it meant I could record overnight without having to stay up!

The first way is as follows:

TheRecorder.StartNow((Istrib.Sound.SoundCaptureDevice)
	(SoundCaptureDevicesCmb.Items[SoundCaptureDevicesCmb.SelectedIndex]));

(Note: Even if you have already set the sound capture device, it must be passed again to make sure that one has been set.)

The second way is just as simple with only two extra parameters, StartTime and EndTime. StartTime is the time (accurate to hour and minute, not day or second) that you want recording to begin. EndTime is the nominal time you want recording to end. Recording is told to stop at this time, however, recording continues until the track playing when the EndTime is reached has finished. This ensures that you don't get only half a track recorded, however, if you are recording long audio books, you may want to work out what time recording will end before setting the EndTime!

The code for starting and ending looks like this:

TheRecorder.StartWaiting(dateTimePicker1.Value, dateTimePicker2.Value, 
			(Istrib.Sound.SoundCaptureDevice)
			(SoundCaptureDevicesCmb.Items
				[SoundCaptureDevicesCmb.SelectedIndex])); 

TheRecorder.StopWaiting();

It's that easy! ;D

Some other properties that I have included are Recording and Waiting. Recording returns whether the application is still recording even if the EndTime has been reached/passed. Waiting returns whether the application is waiting for either a StartTime or EndTime to be reached (no distinction is given).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ed Nutting
Founder
United Kingdom United Kingdom
Hi there, so you're reading this? I probably ought to tell you something helpful then...
 
Okay well, I'm 17 from London, UK and I have been programming since I was 8 years old. You'll see from my profile I've dabbled in a lot of different areas and I do know what I'm talking about so as they say "gimme some respect yeah?" Smile | :) I've done GCSE's (got 7A*'s, 2A's and a B in French) and am now studying for my AS-Levels (Math, Further Maths, Physics and Chemistry). My main aim is to go to university to study electronic engineering and then work in robotics (preferably humanoid but most of the field is interesting).
 
Thanks for reading,
Edward Nutting
Follow on   Twitter

Comments and Discussions

 
Questionerror while run the software PinmemberMember 1052461414-Jan-14 22:00 
Questioncant get the application to start Pinmemberclwprogrammer14-Aug-11 12:23 
AnswerRe: cant get the application to start PinmemberEdMan19620-Aug-11 21:00 
GeneralRe: cant get the application to start Pinmemberclwprogrammer20-Aug-11 21:37 
GeneralRe: cant get the application to start PinmemberEdMan19620-Aug-11 21:48 
GeneralDownloads do not work PinmemberJohann Krenn27-Aug-10 23:16 
AnswerRe: Downloads do not work PinmemberEdMan19628-Aug-10 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 28 Aug 2010
Article Copyright 2010 by Ed Nutting
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid