PowerBuilder Tips, Tricks, and Techniques

Berndt Hamboeck

Subscribe to Berndt Hamboeck: eMailAlertsEmail Alerts
Get Berndt Hamboeck: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


PowerBuilder: Article

PowerBuilder Goes MP3

PowerBuilder Goes MP3

In this article I'll show you how to play MP3 files with your own "sound machine" written in PowerBuilder. But before we start to implement it, you should first understand what MP3 is. MPEG-1 Layer III, MPEG Audio Layer III, or MP3; it's all the same. I'll use the name MP3 from now on. Fraunhofer Gesellschaft (FhG) situated in Germany was the original company/founder in the development of the MP3 standard and received patent protection for it in 1989. The original name was EUREKA project EU147, Digital Audio Broadcasting. Dieter Seitzer, a professor at the University of Erlangen, and a team developed an algorithm, called the ISO-MPEG Audio Layer-3 standard. MP3 is simply an audio format that compresses a music track to MP3. The audio file format on a music compact disc is called WAV, a standard digital format for audio files that offers the best quality. At the same time these files are very large (10MB/min.), because samples are stored "in the raw" where no preprocessing is required other than the formatting of the data. The WAV file itself consists of three parts:
1.   RIFF: 12 bytes long and identifies the file as a WAV file
2.   FORMAT: 24 bytes long and identifies parameters such as sample rate
3.   DATA: Contains the actual data That's why they are unsuitable for everyday exchange via the Internet. The MP3 compression process detects any unneeded or empty data in a WAV file and effectively omits it. The resulting file is called an MP3 and is approximately one-tenth the size of the original WAV. The MP3 doesn't suffer from any noticeable loss in quality, and its smaller size makes it ideal for transfer across the Internet. February 1999 was the first time music tracks were issued in MP3 format. Since then, the popularity of MP3 has grown rapidly and about 70 million users worldwide are engaged in MP3 file sharing, which also causes some problems. Legal Matters
The Home Recording Act allows you to make copies of your music CDs for personal use, but by law you're not allowed to distribute or share these files with friends if they don't own a copy of the material you copied. MP3 is not an illegal audio format, but when people offer MP3 versions of copyrighted material it's considered copyright infringement. The Recording Industry Association of America will investigate the illegal production and distribution of sound recordings. They say they won't target people downloading songs, but they have no mercy (up to three years in prison and $250,000 in fines) for those posting a lot of songs on a site for download. PowerBuilder MP3 Player
The implementation of an MP3 player in PowerBuilder is easy; you need the WINMM.DLL on your system (and, of course, you need a sound card). This Windows API contains several functions that will enable you to play music files. We'll use two functions (the full source code can be found on http://powerbuilder.codexchange.sybase.com in the General section):
  • mciSendString: Used to send English-like string commands to a multimedia device. To play an MP3 file, first open the "waveaudio" device, then issue a "play" command using an alias:

    cmdToDo = "open " + as_FileName + " type MPEGVideo Alias MP3Play" Since the mciSendString doesn't like long filenames with spaces, you have to use the GetShortPathName API to convert a long pathname to a short one.

  • mciGetErrorString: If we encounter errors with the mciSendString command, this function returns an error string that we can use in a MessageBox. Listing 1 provides a complete implementation of the play function. Conclusion
    For those of you who are interested in music, MP3 is a great technology. It makes it a cinch for you to play DJ and mix and match your favorite songs, bands, or styles of music. Another advantage of MP3 is that there are no security features associated with the files, so a lot of them are posted on the Web every day. The files are small enough to be downloaded easily, or even attached to an e-mail and sent to a friend. Have fun with MP3s and PowerBuilder!
  • More Stories By Berndt Hamboeck

    Berndt Hamboeck is a senior consultant for BHITCON (www.bhitcon.net). He's a CSI, SCAPC8, EASAC, SCJP2, and started his Sybase development using PB5. You can reach him under [email protected]

    Comments (1)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.