Accessibility

Table of Contents

Building a live DJ application for MP3 files

Building the server-side code

Before you get started, let's discuss the application you are building and define the desired functionality.

This project started out as a simple application designed to stream MP3 files to multiple computers. Rather than allowing random audio streaming—playing MP3 files that are sitting on the server—the goal of this application is to stream specific MP3 files to audience members, as though they are listening to a DJ on a radio station. To achieve this goal, you'll need to set up the DJ application as a remote audio controller that dictates when the MP3 files will play on the server, and have your audience (the users connected to the application) subscribe to the audio stream.

By configuring the application in this fashion, the songs heard by the audience members should be synced up (depending on the speed of their Internet connection) and all connected users will hear the same song. As you go through the steps to create this application, I'll cover important information regarding server-side streams, server-side shared objects, and how to access them both from the client side. You will also learn why it is helpful to use this approach when building this type of application.

To begin, you'll need to establish a set list of songs (MP3 files); you'll also need to set up two lines of audio output. The two lines are created to add transitions between the songs, fading the previous song out while fading the next song in. The list of songs displayed in the application's interface allow the DJ to choose which MP3 files to play and to set each selected song into one of the two audio output lines. As an extra bonus, I'll show you how to add a microphone so that the DJ has the ability to talk directly to the audience over the stream.

It is important to note that the interface of the completed application will be controlled by the DJ. The selection of songs, use of the microphone, and audio output levels are determined by the interface settings. In contrast, the audience members are merely listening, as though they are turning on a radio. Their participation involves opening the application, connecting to the stream, and listening to what is playing.

Let's get started. Begin by gathering a folder of MP3 files. Once you have the files, the next step is to place them on the server. To accomplish this, there are two choices. The first option is to put the MP3 files into a "streams" folder in the application you are going to connect to, to make the songs available for playback. The second option involves putting the MP3 files into a virtual folder that could be anywhere on the server. For the purpose of this tutorial, let's put the audio files in the streams folder inside the application folder.

Call the application folder mp3dj and create it in the applications directory of FMS. Inside the mp3dj folder, create a folder called streams. Then create a subfolder inside the streams folder called mp3djapp that contains your collection of MP3 files (see Figure 2).

Application folder containing the streams folder holding the MP3 files

Figure 2. Application folder containing the streams folder holding the MP3 files

Now that the directories are set up, you can start writing the server-side code. At this stage of development, I usually create a barebones version of the server-side code first, so that I can test the code from the client side later. It is a common practice to write the majority of code in one file (the main.asc file) and then later separate the code into reusable chunks and files like classes. For the purposes of this simple application, I will keep the code all in one file. In a real-world development process, however, the code would be split up, commented, and organized once the desired functionality was achieved. Separating sections of code into different scripts can also make it easier to manage the project and build upon it later.