Editor's Note
MP3 Playlists with Visual Basic .NET
Code download available at:
EditorsNote0304.exe
(132 KB)
Browse the Code Online

Contents
Although it's been several months since the slammer virus hit SQL Server installations, we'd like to offer a public service announcement for anyone who hasn't patched their machine yet. PATCH YOUR MACHINE NOW! We found out the hard way that it can hit any machine that runs SQL Server and is attached to the network. You might not notice any symptoms at first—we thought that our network router had gone bad because no one could get a lease from the DHCP feature on it. It turns out that the outgoing network storm from the one infected machine was tying up all networking to such an extent that the router couldn't get a word in edgewise. If you start to have weird network problems, take machines offline one by one until they magically go away. Or check Task Manager—if sqlservr.exe is taking up more CPU than the System Idle Process, it might have been compromised.
An even simpler solution is to visit the
Microsoft SQL Server site. In addition to the SQL Server SP3 patch that fixes this vulnerability, the product support team has created a program that will scan your network for unsecured instances of SQL Server and tell you where they are. It's up to you to stop SQL Server services on that machine and then patch it appropriately. Patching production products might be a nuisance, but it sure beats the alternative.
MP3 Playlist Editor
For the second part of this month's Editor's Note, we refer you first to a communication we had from an old acquaintance not long ago. "Hey Ed.," the note began, "remember me? Chris! We met at that Coast Guard dance a few years ago. Listen, I just got the same MP3 player you did, but I don't know how to make playlists for it. Got any ideas?"
Leaving aside for a minute the fact that we've never been to any Coast Guard dance and we have no idea how Chris knows we own the same 20GB MP3 portable player as he does, this note got us to thinking. It couldn't be that hard to write one of these ourselves. After all, a playlist (commonly saved with an .m3u extension) is just a plain text file containing paths to MP3 files.
It would be easy to write a program that looped through a path recursively, searching out all files with an .mp3 extension, then letting the user select any or all of them for a list that then got written out to a file. The System.IO.Directory namespace of the .NET Framework provides a GetDirectories member function that places all subdirectory names in a string array (which can then be recursed in a function), and GetFiles does the same thing for all the file names you need to look at.
But MP3 files contain a lot of tagged data, from song and album name to artist to track number. There are several dozen possible tags (listed at
http://www.id3.org/id3v2.3.0.txt). While most of these tags aren't used in the majority of MP3 files, one tag quickly caught our eye—APIC, which represents the embedded cover image of the album the song is found on. This got us to thinking how we could doll up the program even further.
It just so happens that the data found after this tag provides length information, a couple of flags, and a stream of data representing the image (usually JPEG format). You just read the data out of the file and into an array of bytes, and...what? Before the .NET Framework, it would have been a hassle to get this data into some sort of image or picture control. But now anyone with Visual Basic .NET and five minutes on their hands can do it. All you have to do is take the array of bytes, create a MemoryStream from it, and create an Image using the FromStream method. Thanks to the .NET Framework, you can take an array of bytes holding JPG data and display it as an image in a PictureBox control in as little as one simple line of code, as shown here:
picCover.Image = Image.FromStream(New MemoryStream(jpgdata))
How cool is that? If you use only one .NET Framework trick this year, make it the direct memory bitmap copy one.
We continue to be the only Editor's Note with a code download, and the full source code for this MP3 Playlist Maker, an application in progress, can be downloaded from the link at the top of this article. We've just added a ListView, so that you can create a playlist by song name instead of by file name. And it works great on these high-capacity MP3 players! If you have any tweaks or additions to this program, find it useful, or have any features you might like to see implemented in a future version of the Editor's Note, please feel free to drop us a line at
mmeditor@microsoft.com.
Active Directory, ActiveX, IntelliSense, Microsoft, MSDN, Visual Basic, Visual C++, Visual C#, Visual Studio, Windows, Windows NT, and Win32 are registered trademarks of Microsoft Corporation. Other trademarks or tradenames mentioned herein are the property of their respective owners.
MSDN Magazine does not make any representation or warranty, express or implied with respect to any code or other information herein. MSDN Magazine disclaims any liability whatsoever for any use of such code or other information.