|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis project was inspired by an obscure piece of VB.NET code I found one day on a forum (and never saw again). This code wrapped MCI and enabled you to select a specific track from a CD and play it. The class design was already established, but the functionality was very limited and flawed in some places. I rewrote the class design in C# and added functionality to give access to all the necessary features you would expect in a comprehensive library. I would like to give credit to the authors of the original VB.NET class, but sadly don't know who they are. Using the DeviceController.CDDevice classFirst add a reference to the DeviceController.dll, and then include the using DeviceController;
Instantiate the CDDevice CDAudioObject = new CDDevice();
Now we can really get started. To set the drive device to read from, you simply use a statement like this, where 0 is the first device available: this.CDAudioObject.ChangeDrive( 0 );
To encapsulate the task of detecting drive devices, I've included a property that gets an foreach(string Drive in CDAudioObject.Drives)
{
this.DriveView.Items.Add(Drive);
}
The next thing you will probably want to do is detect how many tracks are on the CD. int tracks = this.CDAudioObject.TotalTracks;
The class assigns the first track on the CD as the current track, as soon as you select a device with a CD in it. So, as soon as you select a drive, you can start playing. To play, pause or stop a track from playing, simply use the following method calls: this.CDAudioObject.Play();
this.CDAudioObject.Pause();
this.CDAudioObject.Stop();
Likewise, you can call methods to move forward or backward through the tracks. If you try to move past the limits of the track range of the CD, the method call will simply do nothing. this.CDAudioObject.Next();
this.CDAudioObject.Previous();
To physically open and close the currently selected device, you can call the this.CDAudioObject.Eject();
So that's the core functionality. I've also included a range of properties to access information about the length, current position etc., for CDs and their tracks. It's worth noting that I've doubled up on some of these properties, providing a property that gives a formatted string (such as
Demonstration ApplicationI've written a demonstration app that implements pretty much every piece of functionality from the class library. I think it works pretty well, but don't be too critical of it. It's mainly to provide an example of how you could use the different aspects of the class library. ConclusionHopefully this class can be of use to developers, if only as a base to implement functionality on top of. It'll probably be redundant in a couple of years when Longhorn gets released anyway. I was looking at the GAC assemblies that are packaged with LongHorn the other day, and there are a range of assemblies dealing solely with multimedia and audio. Something that's been missing from the .NET framework since it was released. Can't wait. :-)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||