Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Audio Manager Jukebox for the PRISMIQ Media Player

0.00/5 (No votes)
2 Jun 2004 1  
Desktop server and Pocket PC Smart Client for the PRISMIQ Media Player.

Server Screenshot

Pocket PC Screenshots

Introduction

Several companies have introduced networked media players over the last couple of years. These media players allow you to stream audio, pictures and video from a local PC directly to your home entertainment center via a wireless or wired network connection. Some examples include:

Background

PRISMIQ Media Player The Audio Manager server and pocket PC Smart Client is designed to control the PRISMIQ Media Player from a desktop and wireless Pocket PC. PRISMIQ provides documentation for controlling their Media Agent via a simple command interface. They also provide a JSP code sample, which will run in any browser including a pocket PC. Based on the PRISMIQ JSP code sample The Audio Manager for the PRISMQ Media Player was born.

Audio Manager The following criteria were considered important in the design of the Audio Manager:

  • The User will be able to add any combination of songs or playlists to the audio queue.
  • The system should support multiple clients with changes updated transparently on each client.
  • Both desktop and pocket PC clients will be supported.
  • Clients will communicate with a server application, and will not be required to remain on to control the audio stream.
  • Updating clients should be quick and network traffic should be minimized.

Using the code

The Audio Manager consists of two separate applications. The server is a desktop application written in C#. The server maintains a queue of songs from which it and client applications append to. The server communicates with the PRISMIQ Media Agent, transferring song Ids from the queue to the Media agent. The Client is Pocket PC application written in C# and the compact framework. The client contains the same user functionality as the desktop server but does not maintain a song queue or communicate with the Media Agent. Instead the client forwards all queue requests to the server via UDP network requests. The client server communications consists of a single byte command followed by any command data. Commands are as follows:

Server Command Data Description

  • 00 Skip Skip to next song (sent by client)
  • 02 Add SongID Add song to the queue (sent by client)
  • 04 Get Queue Request transmission of server queue (sent by client) 06 Play Start playing first song in the queue (sent by client)
  • 08 Pause Pause current song (sent by client)
  • 0A Shuffle Shuffle the server queue (sent by client)
  • FE Ping Request Request a server ping (sent by client)

Client Command Data Description

  • 01 Next Song Next song in queue started (sent by server)
  • 05 Queue SongID1… SongIDn Dump of song Ids in the queue (sent by server)
  • FF Ping QueueCRC SongElapse Ping from server sent every second contains a CRC of all Song Ids in the queue and the elapse time of the current song in seconds
  • *** SongID is a 32 bit unsigned integer
  • *** SongElapse is a 32 bit signed integer (if negative audio is paused)

Most commands are self-explanatory however the ping command (sent by the server every second) contains a CRC of its queue. This allows the client to readily verify its queue after a power on. If the server ping CRC does not match the CRC of the client queue the client sends a “Get Queue” command to the server.

XML Media Files

The PRISMIQ media manager generates two XML data files, Media.xml and PlayList.xml, which contain information about the audio, video and pictures on the users hard drive.

The audio entries have the following format:

Media.xml

<xml> 
 <audio> 
  <title>moondance</title> 
  <id>1528298868</id> 
  <type>mp3</type> 
  <runningtime>4:14</runningtime> 
  <released>2003</released> 
  <genre>default</genre> 
  <bitrate>128 kbps</bitrate> 
  <path>C:\Music\Michael Buble\MICHAEL BUBLE</path> 
  <artist>Michael Buble</artist> 
  <album>MICHAEL BUBLE</album> 
  <tracknumber>2</tracknumber> 
  <filename0>C:\Music\Michael Buble\MICHAEL BUBLE\Michael Buble - moondance.mp3
  </filename0> 
 </audio> 
 <audio> 
  <title>Ka-Ching!</title> 
  <id>1625257760</id> 
  <type>mp3</type> 
  <runningtime>3:21</runningtime> 
  <genre>default</genre> 
  <bitrate>128 kbps</bitrate> 
  <path>C:\Music\Shania Twain\Up!</path> 
  <artist>Shania Twain</artist> 
  <album>Up!</album> 
  <tracknumber>12</tracknumber> 
    <filename0>C:\Music\Shania Twain\Up!\Shania Twain - Ka-Ching!.mp3
    </filename0> 
 </audio> 
</xml>

PlayList.xml

<xml>
    <playlist>
        <name>MICHAEL BUBLE</name>
        <type>audio</type>
        <sortcolumn>track number</sortcolumn>
        <sortdirection>Ascending</sortdirection>
        <entry>453215480</entry>
        <entry>1528298868</entry>
        <entry>529725513</entry>
        <entry>2590241737</entry>
        <entry>3769760375</entry>
        <entry>1551272395</entry>
        <entry>2438010674</entry>
        <entry>1502551820</entry>
        <entry>231886403</entry>
        <entry>512290532</entry>
        <entry>1973482017</entry>
        <entry>2603685597</entry>
        <entry>843667268</entry>
    </playlist>
    <playlist>
        <name>Up!</name>
        <type>audio</type>
        <sortcolumn>track number</sortcolumn>
        <sortdirection>Ascending</sortdirection>
        <entry>613994627</entry>
        <entry>2816411363</entry>
        <entry>2391023110</entry>
        <entry>1146468105</entry>
        <entry>2596739105</entry>
        <entry>780673557</entry>
        <entry>610118837</entry>
        <entry>810715573</entry>
        <entry>939504637</entry>
        <entry>2415083396</entry>
        <entry>1630180877</entry>
        <entry>1625257760</entry>
        <entry>2401281999</entry>
        <entry>3963164466</entry>
        <entry>3173191139</entry>
        <entry>3565712766</entry>
        <entry>1333699249</entry>
        <entry>4250617949</entry>
        <entry>3074224152</entry>
    </playlist>
</xml>

The Media agent requires the ID contained in the <id></id> tag of Media.xml to play the given song. The server and all clients must contain copies of these files in order to reference and queue songs. The Pocket PC client currently looks for these files in the executable directory, where as the servers path can be set.

Program Code and flow

Both the server and client applications share a common code base and operate similarly from both a user standpoint and program flow. The main differences are:

  • Differences between the .NET compact framework and the full desk top framework
  • Server communicates with the PRISMIQ media agent
  • Server or client commands

Some Notes:

  • The pocket PC client application requires the compact framework V1.1 SP2 or later, available from Microsoft
  • The Pocket PC client will not work under emulation as the UDP classes do not seem to work under emulation.

Program flow:

Each application loads the Media and Playlist XML files and generates two hash tables. One for songs (Media.xml) and one for Playlists (playlist.xml). A treeview displays the contents of these hash tables in either a song view or a playlist view.

The server establishes a TCP connection to the media agent.

Opens a UDP client or server connection. The server starts transmitting Ping commands every second. The Client listens for Ping command from the server.

Start a one second timer. The server uses this to send Ping commands to the clients an update elapsed time. The client uses this as a timeout if Pings are not received from the server and displays a wait cursor if no server ping was received in the last two seconds.

Each application waits for one of the following events to occur:

  • A user triggered event (Add a song to the queue, Play Next or Pause)

The user adds songs to the queue by “double clicking” (desktop) “Tap and Hold” (pocket PC) a song or playlist from the treeview. On the server the song is added to the queue and a new queue CRC is calculated and sent to all clients. On the client the song will be added to the local queue and a local queue CRC is calculated.

The Add Song command is sent to the server.

The Play event - On the server the first song in the queue is sent to the media server. On the client the Play command is sent to the server. The Next event On the server the next song in the queue is sent to the media server. The Queue CRC is calculated On the client the Next command is sent to the server.

The Pause Event (toggle event) - On the server a pause or play command is sent to the Media Agent if paused the elapsed time in the server ping becomes negative. On the client the Pause command is sent to the server.

A server or client command received - On the server most commands received from the client mirror the user events above, with the exception of Get Queue, Get Queue sends the entire song queue to the client. The client receives a ping command from the server every second. The ping command contains the server queue CRC and the song elapse time. If the server CRC is different from the clients local CRC the song queue is requested from the server. The ping command also updates the statistics page with the elapsed time.

A media agent message (server only) - The media agent has two messages that the server is interested in. An end of song message tells the server to queue the next song. A song not found message also queues the next song. The Next Song command is sent to all clients. Both the server and clients remove the head of the queue and recalculate their queue CRC.

Operation configuration

Audio Manager Server - You must enable the media player agent to allow external communications File Setup displays the Configuration dialog Media Player Address (address of the Prismiq media Player) Port (Media Player port default = 2253)

Media Server - XML Files Location of media.xml and playlist.xml Server Address (address to communicate to clients) 255.255.255.255 is the default it can be any UDP broadcast address or a specific client address (if there is only 1 client) Port (Port to communicate to clients) Must be the same as set on the clients Tool bar buttons Playlist (Tree View) Song (Tree View) Play Next Pause To select media into the queue double click on either a song or a playlist in the Tree View

Audio Manager Client Pocket PC - You must copy playlist.xml and media.xml to the same location as the executable on the pocket PC File Setup displays the Configuration dialog Address (address to communicate to server) 255.255.255.255 is the default it can be any UDP broadcast address or a specific server address (**recommended) Port (Port to communicate to the server) Must be the same as set on the server To select media into the queue Tap And Hold on either a song or a playlist in the Tree View If Tap And Hold does not automatically select the tree item you will need to update the compact framework on the pocket PC to version 1.0 SP2 Tap And Hold songs in the queue to display song details

Points of Interest

Links:

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here