The code on the main level of the application, initialises the File and Multimedia services of Capuchin, preparing the whole environment of the MP3 Player. This screen also creates a key listener to interact with the Left and Right navigation keys, which allows the user to skip or go back to a song without opening the playlist.



The Soft Keys component (softKeys_sks instance) is always visible and is responsible for switching views, for playing or pausing a song, for selecting a new song or exit the application.

There are three Soft Keys: left (LSK), middle (MSK) and right soft key (RSK). Their labels can be customised either using the Parameters panel (Window > Properties > Parameters) or using code.

The instance placed on stage already has its labels customised via the Parameters panel with the following values:

Parameter Value
LSK content (text or path) "Playlist"
MSK content (text or path) "Play"
RSK content (text or path) "Back"

The Soft Keys labels vary when the playlist view is loaded or when the song state (playing or paused) changes. This modification during runtime is possible using ActionScript code.

The code below shows the customisation of MSK when the song starts to play:

softKeys_sks._MSK = "Pause";

The following table shows all the values that each soft key can assume in the application:

  LSK label MSK label RSK label
Application starts "Playlist" "Play" "Back"
mcPlayer view is loaded "Playlist" "Play" "Back"
A song starts to play with mcPlayer view loaded "Playlist" "Pause" "Back"
A song is paused with mcPlayer view loaded "Playlist" "Play" "Back"
mcPlaylist view is loaded "" "Play" "Back"


The Soft Keys component dispatches two events when any soft key is selected: onSoftKeyDown (when a Soft Key is pressed) and onSoftKeyUp (when a Soft Key is released). This application uses the onSoftKeyDown event with the following structure to respond to user interaction:


The function of each soft key may vary according to the selected view, since the views can redefine the Soft Keys onSoftKeyDown event handler.

The openScreen method allows the user to switch between views. The following code is implemented on the left soft key of main frame 1:

  

openScreen("Playlist");

If the application does not have songs to play, LSK and MSK are disabled to avoid unauthorised interactions:

   

softkeys_sks._isLSKEnabled = false;
     softkeys_sks._isMSKEnabled = false;

The Text component (txtTitle_txt, txtAuthor_txt, txtAlbum_txt, txtPlaybackTime_txt instances) is used on mcPlayer view to provide information about the current song. If there is no file to open, it is used to display a warning message.

   

txtTitle_txt._text = mediaTitle;
     txtAuthor_txt._text = mediaAuthor;
     txtAlbum_txt._text = mediaAlbum;
     txtPlaybackTime_txt._text = formatTime(mediaPlaybackTime);

The Progress Indicator component (progressTime_pgi instance) is placed inside the mcPlayer view (for more information, see “mcPlayer Frame 1 – Player definitions” on page 13. If the view is loaded or reloaded, the current progress of the song must be set, otherwise the component may not work:

  

progressTime_pgi.setProgress(mediaPlaybackTime);

And also the Progress indicator maximum value should be set:

  

mcContainer_mc.mcScreen_mc.progressTime_pgi._maximum = mediaDuration;