How To Create A Music Review Site

ADDING AUDIO FIELDS -- Red Queen Tutorial 07

Adjust Text:  a a a a
« Red Queen User Manual   |   Tutorial Table Of Contents   |   Obtain Red Queen »


ADDING AUDIO FIELDS

Definition of a Field

So far in this tutorial we have seen our garage band webmaster Mike set up his Supplier table to represent the profiles of garage bands that submit themselves to his site. Now we want to see how he goes about configuring his Item table to represent audio tracks and video clips. To make it interesting, we will allow for the possibility that a record in the Item table can represent from one to three audio tracks, plus up to three optional video clips--a band sampler, if you will.

If we look at the default columns of the Item table we see that Mike already has the core elements in place to describe the garage band offering. The columns include:

  • Item.known_as (the title field)
  • Item.description
  • Item.keywords

There are also Item.url, Item.url_mouseover, and Item.url_status fields which deal with an associated URL for the record. If Mike was going to use records in the Item table to represent solitary tracks he might have decided to delete the URL fields. But because he intends to allow multiple tracks per record the URL might optionally be used to store the location of an album home page or something similiar. So we will assume he keeps it. Likewise, we assume he keeps the default Item.item_image field, used to store an uploaded image.

Other columns could be added, and the procedure for doing so, as mentioned earlier, has already been covered in some detail in How To Create A Social Network: ADDING EXTRA FIELDS. Here we will just look at how to add columns that can store either audio or video content.

Audio Fields

Show below is the definition of an audio field in Red Queen. That is, this is what the form should look like when Mike goes to create a new column in the Item table that will be used to represent an audio track. The properties of this column are that:

  1. The field will offer an upload manager to allow file uploads on pages dedicated to adding/editing records in the Item table.
  2. The field will allow any visitor to the site to stream (i.e. play) or download the audio file by clicking either on an icon representing the file, or the filename itself.
  3. The field will store and report the size of the audio file and its MIME type.

Before discussing how Mike can add audio columns manually, it is worth noting that audio columns (and any of the auxiliary audio columns also discussed below) can be added in bulk. See the section at the bottom of the page which discusses bulk column additions.

To add an audio file column Mike would visit the Database control panel, select the Item table in the first drop down menu on the left of the page, then select Columns in the second drop down menu. At the bottom of the resulting page which appears (showing the definition of each column in the table) he would find a link to Add Column. Following that, he would be presented with a form similar to the one shown below (which is shown here filled in such a way that it will generate an audio file column when submitted):


AUDIO Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


Note that the column is an UNSIGNED (i.e. non-negative) INTEGER and NOT a URL. The uploaded audio file is represented in the record as a numeric value which is converted into a download URL when a link needs to be generated and placed on the page.

The column has its Not Null attribute set to Yes. This means that it is a required field. If someone attempts to create a record in the Item table WITHOUT supplying the first audio track they will simply be unable to proceed. Thus, at least one audio track is required. If we add more audio track columns they too can be required fields if we like, but more likely we will simply set their Not Null attribute to No so that extra tracks can be considered optional.

The form element named Form Type is chosen to be PUBLIC_AUDIO. This means the file will be assumed to be an audio track when the time comes to present a download (or streaming) link. If any specific treatment common to audio files should take place, this designation as a PUBLIC_AUDIO file alerts Red Queen that this file should be treated as such. Note that anyone can download a PUBLIC_AUDIO file. Had Mike decided instead to give the column a PRIVATE_AUDIO Form Type, only registered members who are logged in would be able to download it (a CGI script would spool the file in that case, rather than have the webserver explicitly handle the request--PRIVATE files are therefore slower to download). One should always chose to make download files PUBLIC if there is no good reason for not doing so. Also, only PUBLIC_AUDIO files can be handled by the Wimpy Players.

The column has been named audio_01. Additional audio track columns would be named audio_02 and audio_03 in our example. Likewise, the Form Display value (the label which appears next to the file upload box) is Audio Track 1. Additional audio columns would have a Form Display of Audio Track 2 and Audio Track 3 (this naming convention is not mandatory, but it is recommended because it is extensible--we can add more at any time--and it is clear what the columns represent when named this way). The extra 2 audio columns will have a Not Null value of No so that they are NOT required columns--meaning only the first audio track must be uploaded, while the additional ones are optional.

Audio Title Fields (Recommended)

Because Mike is allowing multiple files to be uploaded with each Item record, it might be useful to attach a label to each of the audio files. This would not be necessary if he allowed just a single uploaded audio file because there is already a known_as column in the table which can be used for the title. But because he is allowing up to 3 audio tracks in this example we will assume that Mike adds a label column for each uploaded file. He does this by adding three VARCHAR(32) columns of the following type (the length of the string held by the column could be any number up to 255, but 32 is generally enough for a short descriptive title):


AUDIO TITLE Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO TITLE Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


The choice of the column name is NOT arbitrary. The name of a column that represents the title of an audio file column MUST be the same as the name of the audio file column, but with the suffix '_title' appended to the end of it. Thus if audio_01 is the name of the audio column, the corresponding audio title column, if it is defined, should be audio_01_title. The Not Null attribute should generally be set to No for titles so as to make them optional. If the audio file column itself is optional, then the title columns should definitely be optional too.

Finally, if you intend to use the Wimpy MP3, AV, or WASP player to include your tracks on the page, you will be interested to know that the title column specified above will be used to populate the <title> tag of the XML playlist file that will be used to represent the audio tracks for a given record in your table (see more about the Wimpy Players elsewhere in this tutorial).

Audio Artist Fields (Optional)

Another optional column which Mike might have used to represent additional information associated with audio columns is an artist field, to hold the name of the person, or persons, who created the content. An <artist> field is supported by Wimpy XML playlists (so that the name of an artist can also appear in the Wimpy MP3 Player when the track is being played). This is the reason it is supported in Red Queen. Mike doesn't need such a column, but he might add it as optional data that his garage band member could supply if they wished. The nature of this column is virtually identical to the title column he added to support the audio column. Again, this might be a VARCHAR(32) column:


AUDIO ARTIST Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO ARTIST Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


Again, the choice of the column name is NOT arbitrary. The name of a column that represents the artist (or artists) associated with an audio file column MUST be the same as the name of the audio file column, but with the suffix '_artist' appended to the end of it. Thus if audio_01 is the name of the audio column, the corresponding audio artist column, if it is defined, should be audio_01_artist. The Not Null attribute should generally be set to No for artist columns so as to make them optional. If the audio file column itself is optional, then the artist column should definitely be optional too. When the column is populated its value will be used to populate the <artist> tag of the Wimpy XML playlist file.

Audio Album Fields (Optional)

Due to the fact that an <album> field is supported by Wimpy XML playlists (so that the name of an album associated with the track can also appear in the Wimpy MP3 Player) such a column is also supported in Red Queen. Mike almost certainly doesn't need such a column, because his garage bands very likely have no albums to boast of, but it is discussed here for the sake of being complete. The nature of this column is again virtually identical to the title column he added to support the audio column. The name of an album can be represented by a VARCHAR(32) column:


AUDIO ALBUM Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO ALBUM Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


As was the case for other audio column related fields, the choice of the column name is NOT arbitrary. The name of a column that represents an album name associated with an audio file column MUST be the same as the name of the audio file column, but with the suffix '_album' appended to the end of it. Thus if audio_01 is the name of the audio column, the corresponding audio album column, if it is defined, should be audio_01_album. The Not Null attribute should generally be set to No for album columns so as to make the album name an entirely optional piece of information. If the audio file column itself is optional, then the album column should definitely be optional too. When the column is populated its value will be used to populate the <album> tag of the Wimpy XML playlist file.

Audio Running Time Fields (Recommended)

A critical piece of information when dealing with large files that are intended to be streamed, such as audio or video files, is the running time. It is a good idea to add such a field for each audio file column that is added to the record. At the database level this field needs to remain optional (a Not Null value of No) for every audio field that is itself optional. Because we are dealing with a time interval that may be measured in hours, minutes, and seconds, it is a good idea to use the DATE_SELECTABLE Form Type to characterize the input element used to collect the time interval. Here is how a running time column would be defined:


AUDIO RUNNING TIME Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO RUNNING TIME Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


A column which is of MySQL TIME type (which is used to store time durations of the form hours:minutes:seconds) can presently only be presented one way when collecting or displaying the time duration, so the value of its Form Type is not important. But we select DATE_SELECTABLE, as it is as good as any other date/time like column representation.

The default that has been supplied for the column is 00:00:00 which represents a zero-duration time interval. As an editable form element present on a page it would look something like the following:

hours mins secs

Displayed on a detail page the same value would render as 01:08:53. If you use Wimpy to present your tracks, this duration (i.e. running time) field will also be converted into seconds and made available for the <seconds> tag in the XML playlist file.

Audio Image Fields (Recommended)

You may of course add as many image fields to a record as you wish, and these will normally be presented as gallery images on the detail page. Adding such columns, which have the Form Type value of PUBLIC_IMAGE, has been covered, for example, in the Image Fields section of Tutorial Three. However, you can also specify that an image field should represent the cover art associated with an audio track when you will be using one of the Wimpy MP3 Player skins that supports cover art (shown when the user clicks on the audio track associated with the image). Such cover art will also be used to populate a click-to-play image gallery that can be presented in addition to the selected Wimpy Player for the audio tracks.

Here is how Mike would add a cover art field for his first audio track field, which he called audio_01 in a previous section. He simply sets up a standard PUBLIC_IMAGE field, but he takes care to name the column by adding a _visual suffix to the name of his audio track column:


COVER ART Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

COVER ART Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No

The reason for using the mandatory _visual suffix when naming the column is that this will indicate to Red Queen that the URL for the cover art should be used to fill the <visual> tag of the Wimpy XML playlist file for the record.

Audio Description Fields (Recommended)

If Mike was adding just a single audio column there would probably be no need to add another description column, because we already have one available to us--the Item.description field. However, if he is adding multiple audio columns it CAN be a good idea to give each audio column its own separate description. In particular, if using the Wimpy MP3 or WASP Player to present audio tracks, it is very useful to add description fields because these can be presented as part of the information bound up in the image gallery presentation. Liek the title column, the description can probably be characterized by a short text field, like the VARCHAR 128 column format:


AUDIO DESCRIPTION Column Properties

Column Name

 

Column Type

 

Column Size/Precision

 

Column Values

 

Attributes

 

Not Null

 

Yes No

Extra

 

An AUTO INCREMENT column already exists

Column Position

 

Default

 

Search Weight

 
 

AUDIO DESCRIPTION Form Properties

Form Display

 

Form Type

 

Form Size/Length

 

Form Values

 

Form Regex

 

Hide on Add/Modify Forms

 

Yes   No


Adding Audio Fields In Bulk

If you should decide that you want to allow, say, 10 audio tracks to be uploaded onto each of your detail pages, and you want to offer all the auxiliary audio columns: title, artist, album, duration, description, and visual, that comes out to 70 columns in total, just for audio informtion. Adding those columns amounts to fair bit of work. Unless you have a tool to add them all in bulk...

You can add multiple audio columns to the Item, Member, or Supplier table using the Red Queen record importer.pl script found in the /do/admin directory. Basically you run the importer in the "add bulk columns" mode, which simply adds coumns without adding any new records. See the section in the user manual on record imports for more information on the general importing process. To add our 70 audio columns to the, say, Item table we would edit this file:

/do/admin/RedQueen/Admin/Import/Config/ItemConfig.pm

In the section dedicated to adding bulk audio columns we would configure the file like so:

add_bulk_audio_columns => 1,

    # information relating to extra AUDIO columns if they appear in the table.
    # these column settings in bulk_audio are ONLY used to add a bunch of columns
    # and require that add_bulk_audio_columns => 1
    #
    # if the column type in the optional_columns hash has a value of 1
    # it will be added as an auxiliary audio column (so toggle as required)
    # ----------------------------------------------------------------------------

bulk_audio => {

       optional_columns => {

           title       => 1,
           artist      => 1,
           album       => 1,
           description => 1,
           duration    => 1,
           visual      => 1,
       },
       column_prefix              => 'audio_',      ## prefix for audio columns
       column_form_display_prefix => 'Audio Track', ## prefix form display, ALL audio cols
       title_form_display_suffix  => 'Title',       ## suffix for title form display
       artist_form_display_suffix => 'Artist',      ## suffix for artist form display
       album_form_display_suffix  => 'Album',       ## suffix for album form display
       description_form_display_suffix => 'Description',  ## suffix description form display
       duration_form_display_suffix    => 'Running Time', ## suffix duration form display
       visual_form_display_suffix      => 'Cover Art',    ## suffix visual form display
       after_col_name            => 'item_image',     ## place new columns after this one
       num_columns               => 10,               ## number of new columns to add
       index_start               => 1,                ## starting number for naming columns
    },

Note the first configuration value shown above: add_bulk_audio_columns. This must be set to 1 if the importer is to add audio columns in bulk (else 0, in which case it would function in the normal way as a record importer--as outlined in the section on Importing Records in the user manual).

If we wanted to leave out the duration field from our setup we would set the corresponding value to 0 in the optional_columns hash. After running the importer with the configuration section shown above we would have the following columns added to our Item table:


column Form Display
audio_01 Audio Track 1
audio_01_title Audio Track 1 Title
audio_01_artist Audio Track 1 Artist
audio_01_album Audio Track 1 Album
audio_01_description Audio Track 1 Description
audio_01_duration Audio Track 1 Running Time
audio_01_visual Audio Track 1 Cover Art
... ...
audio_10 Audio Track 10
audio_10_title Audio Track 10 Title
audio_10_artist Audio Track 10 Artist
audio_10_album Audio Track 10 Album
audio_10_description Audio Track 10 Description
audio_10_duration Audio Track 10 Running Time
audio_10_visual Audio Track 10 Cover Art

Obviously you do not want to add that many columns if you have not thoroughly checked the information you have provided in the configuration hash beforehand. The column import mechanism is really only meant to be run once for a given type of bulk column type. You can however add just a single set of audio columns (the first 7 columns) by setting num_columns = 1 and index_start = 1. After adding the 01 set of columns and checking the result you can then set num_columns = 9 and index_start = 2 to get the 02 through 10 sets of audio columns added.

Summary

In this section of the tutorial we have covered the pertinent column types that might be used to add audio file contents to a record. There is nothing to stop us from adding multiple audio columns, named audio_01, audio_02, etc, plus all of the auxiliary columns. For the most part, every column needs to have the Not Null attribute set to No so that adding the information is entirely optional.

Furthermore, these audio files can be presented in several different ways on Red Queen web pages. The default mode of presentation is just to offer a link to the audio file which, when the user right clicks can be downloaded by selecting the Save As option. Or a left click can generally be used to initiate streaming into whatever the default audio player happens to be on the users web site.

The preferred method of audio file presentation, in the opinion of the author, is to use one of the Wimpy Players. The Wimpy MP3 Player is the obvious choice here if you are dealing solely with audio content and have no video files to present as well. However, your MP3s can also be played by both the Wimpy AV and Wimpy WASP players. The most flexible player is the WASP player if you have video and audio to present, but the Wimpy MP3 Player is the most polished, and comes with skins which allow you to select the look of your Jukebox (see Extra Wimpy Skins for ideas, though the Wimpy MP3 Player does itself come with a selection of ready-to-use skins). You can always use the Wimpy MP3 player exclusively for audio files AND one of the other players for video content if you choose. Or you can absorb the MP3 files into the video solution. The choice is yours.

A fuller discussion of the Wimpy Player options is available elsewhere in this tutorial.


Next Section: ADDING VIDEO FIELDS

« Table of Contents


Copyright © 2004 Random Mouse Software. All Rights Reserved.