Creating Now Playing and Summary Templates

1. Introduction
Now Playing and Summary templates in Helium uses a technology called XSLT. XSLT is a script language similar to XML which can be used to transform raw data (XML) into different targets, HTML for example which is used in Helium. Creating templates requires a good knowledge of HTML/CSS and some knowledge of XSLT and XML (especially if you would like to create completely different structures to the default structures). A strong recommendation is that you start to study the XSL templates that are shipped with Helium. The templates can be found as follows: • Now Playing Templates: <helium folder>\Templates\Now Playing • Summary Templates: <helium folder>\Templates\Summary

2. Creating Now Playing Templates
Each Now Playing template comes with two include files that are worthy of closer study (and also reuse to avoid reinventing the same code). The filenames for these helpers are tagconsthelper.xsl which contains a lot of constants related to tags and some basic functions and the other file is named earhelper.xsl which contains more specific helper functions for the Now Playing document. The main template file for a Now Playing template must be named ear.xsl. When a file is replayed in Helium a XML document will be created. This XML document can look like the example below:
1. 2. 3. 4. <?xml version="1.0" encoding="ISO-8859-1"?> <EARData> <ExternalArtistPicture file=""/> <ExternalAlbumPicture file=""/>

Lines 1-4 just contains basic header information.

2.1 Suggested Tracks
5. <suggested-tracks> 6. <track id="1155" artist="Moby" title="Come On Baby (Crystal Method Mix)" rating="0" PlayCounter="0" available="-1"/> 7. <track id="1160" artist="Basement Jaxx" title="Fly Life (Brix Mix)" rating="178" PlayCounter="1" available="0"/> 8. <track id="1163" artist="The Chemical Brothers" title="Elektrobank (Dust Brothers Remix)" rating="0" PlayCounter="0" available="0"/> 9. <track id="1166" artist="The Prodigy" title="Breathe" rating="0" PlayCounter="0" available="0"/> 10. </suggested-tracks>

Lines 5-10 contains all information related to suggested tracks information. Each track item (line 6 for example) contains the following attributes: • • id: Internal Database ID artist: The name of the artist/group

• • • •

title: The track’s title rating: The user rating value. You can use the function RatingToImageFile located in tagconsthelper.xsl to get an image filename matching the rating. PlayCounter: Contains the number of times a track has been replayed. available: Set to zero if the file is not available and -1 otherwise.

A maximum of 10 items can be contained under the <suggested-tracks> node.

2.2 Favourite Tracks
11. 12. 13. 14. 15. 16. 17. <favourite-tracks> <track id="15854" title="One More Time" rating="153" PlayCounter="21" available="-1"/> <track id="14423" title="Make Love" rating="127" PlayCounter="13" available="-1"/> <track id="14427" title="Technologic" rating="102" PlayCounter="61" available="-1"/> <track id="14428" title="Emotion" rating="102" PlayCounter="31" available="-1"/> <track id="5088" title="Alive" rating="0" PlayCounter="40" available="0"/> </favourite-tracks>

Lines 11-17 contains the XML structure used for the <favourite-tracks> node. The item definition are the same as for <suggested-tracks> (described above) and can also contain a maximum of 10 items.

2.3 Albums by artist
18. <albums-by-artist> 19. <album id="992" name="Human After All" picture="C:\Temp\{5B117D00-5C6A-44E7-A74D2D0A0362B127}.jpg" tracks="10" year="2005" rating="102"/> 20. <album id="401" name="Discovery" picture="C:\Temp\ DF892628-319A-47B9-BBDFCD34B3155767}.jpg" tracks="16" year="2001" rating="0"/> 21. <album id="293" name="Homework" picture="C:\Temp\{910D8EBD-9695-4385-9DFB9B50EDFA5382}.jpg" tracks="16" year="1996" rating="0"/> 22. </albums-by-artist>

Lines 18-22 contains the XML structure used to list the available albums from the current artist. A maximum of ten albums can be displayed. Each album has the following attributes: • • • • • • id: Internal Database ID name: The name of the album picture: A path to the album picture. Empty if not available. tracks: The number of tracks on the album year: The album’s release year rating: The album’s rating

2.4 Current Album
23. <current-album> 24. <track id="14419" track-number="1" title="Human After All" available="-1" length="05:19" cd="-1" rating="0"/> 25. <track id="14420" track-number="2" title="The Prime Time Of Your Life" available="-1" length="04:23" cd="-1" rating="0"/> 26. <track id="14421" track-number="3" title="Robot Rock" available="-1" length="04:47" cd="1" rating="0"/> 27. </current-album>

Lines 23-27 contains the XML structure used to describe the full tracklist for an album. The current album XML will exist if you are playing a file from one of the available albums in the <albums-by-artist> node. Each track has the following attributes: • id: Internal Database ID • track-number: The number of this track

• • • • •

title: The title of the track available: Set to zero if the file is not available and -1 otherwise. length: The length of this track, as a formatted string cd: which CD in a set this track comes from. -1 if not available. rating: The track’s rating .

2.5 Track Data
28. <track-data first-played="115 days ago" last-played="71 days ago" playcount="8" picture="C:\Temp\{01CA08D0-3947-4705-9434-3EA879DC7848}.jpg" album-id="992" artist-id="2932" detail-id="14422"/>

Line 28 contains the XML structure for a track-data node. Track data is a combination of internally used data and replaying information. The following attributes are available: • • • • • • • first-played: A text string containing information when the track was first played. last-played: A text string containing information when the track was last played. playcount: Contains the number of times a track has been replayed. picture: A path to the picture for the album from which this track comes from. Empty if not available. album-id: Internal ID artist-id: Internal ID detail-id: Internal ID

2.6 File Data
29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. <FileData type="MPEG"> <FileField name="Location" value="D:\2005\Daft Punk - Human After All\"/> <FileField name="Filename" value="04 - Daft Punk - Steam Machine.mp3"/> <FileField name="Format" value="MPEG 1 (Layer III)"/> <FileField name="VBR" value="0"/> <FileField name="Channels" value="1"/> <FileField name="BitsPerSample" value="16"/> <FileField name="Size" value="7,39 MB"/> <FileField name="Bitrate" value="192"/> <FileField name="Song Length" value="322"/> <FileField name="DurationString" value="05:22"/> <FileField name="Frequency" value="44100"/> <FileField name="Encoder" value="LAME 3.96"/> </FileData>

Lines 29-42 shows the file-data lines XML structure. This XML block exists for both Now Playing templates and Summary (single file) templates. The type attribute in line 29 can have one of the following values: • MPEG – MPEG files • MPC – MPEG Plus files • OGG – Ogg Vorbis files • FLAC – FLAC files • WMA – WMA/ASF files • APE – Monkey Audio’s files • M4A – M4A, M4P and M4B files • CDA – CD Audio tracks

2. 7 Tag Data
43. <tag type="ID32"> 44. <TagField name="TIT2" content="Steam Machine"/> 45. <TagField name="TPE1" content="Daft Punk"/>

46. 47. 48. 49. 51. 52. 53. 54. 55. 56. 57.

<TagField <TagField <TagField <TagField <TagField <TagField <TagField <TagField <TagField <TagField </tag>

name="TALB" name="TXXX" name="TSOA" name="TDTG" name="TRCK" name="TLAN" name="TCON" name="TPUB" name="TDRL" name="TDRC"

content="Human After All"/> description="#HELIUM2 RELEASETYPE" content="2"/> content="Human After All"/> content="2005-03-23T22:42:24"/> content="4/10"/> content="English"/> content="General House"/> content="Virgin Records"/> content="2005"/> content="2005"/>

Line 43 contains a tag rootnode. There can be several <tag> nodes in a Now Playing/Summary document, depending on which tags the source file contains. The type attribute can have one of the following values: • ID32 – ID3v2.x tags • ID31 – ID3v1.x tags • Lyrics3 – Lyrics3v2.0 tags • M4A – M4A/M4P/M4B file tags (QuickTime) • APE2 – APE v2.0 tags • Vorbis – Vorbis tags • ASF – WMA/ASF tags Lines 44-56 shows an example of the contents for a few basic tag types. All constants (name attribute) are defined in tagconsthelper.xsl. In this file there is also a generic helper function defined, GetTagString, which is used to extract the proper tag contents. Please see the example templates for a usage description.

3. Creating Summary Templates
Summary templates are shown on the summary tab in Helium’s Right Sidebar. There are multiple summary files. All these files must exist and must be named: • albumsummary.xsl – Document used when a album is selected • noalbum.xsl – Document used when no album is selected • nofiles.xsl – Document used when no files are selected • summary.xsl – Document used when one file is selected • summarymulti.xsl – Document used when multiple files are selected All these documents must exist in the same folder. They are quite similar to Now Playing templates except for a few things detailed in the sections below.

3.1 Album Summary Documents
The two album summary documents are mainly used from the Album Browser but also from the Media Library when albums are selected.

3.1.1 Selected Album Items
The document albumsummary.xsl will be used to render the album summary. A selected album item looks like the following:
1. <?xml version="1.0" encoding="ISO-8859-1"?>

2. <album name="Trancemaster 1" id="31">

Line 1 contains a XML processing instruction and line 2 contains the album root node, containing two attributes: name – contains the name of the album and id which is an internal database id.
3. <fields> 4. <field name="artist" content="Various Artists"/> 5. <field name="items" content="13"/> 6. <field name="size" content="82"/> 7. <field name="length" content="76:23"/> 8. <field name="picture"><![CDATA[D:\\1992\\Various Artists - Trancemaster Vol. 1\\cover.jpg]]></field> 9. <field name="rating" content="rating4"/> 10. <field name="release-type" content="rt8"/> 11. <field name="release-type-text" content="Compilation"/> 12. <field name="total-cds" content="1"/> 13. <field name="release-year" content="1992"/> 14. <field name="sort-order" content="Trancemaster 1"/> 15. <field name="subtitle" content="Ambient Dance II Trance Chill Out"/> 16. <field name="publisher" content="Vision Soundcarriers"/> 17. <field name="thumb-size" content="128"/> 18. <field name="part-of-series" content="Trancemaster"/> 19. <field name="album-picture-filename" content="C:\Temp\{08D65B73-B15A-4D5F-99850F9C9E2200B2}.jpg"/> 20. <field name="lend-out-date" content="1899-12-30"/> 21. <field name="review"><![CDATA[]]></field> 22. </fields>

Line 3-22 defines all the available fields for an album item. They are all equal and almost self explanatory. However, two fields require some further explanation: Line 8 contains the full path to an extracted album picture. Please note that this data is enclosed in a CDATA structure so that the contents are preserved exactly as entered. Line 21 contains an album review (if available) which is also enclosed in a CDATA structure to maintain exact preservation of the data as entered (Album reviews generally contain HTML markup data).
23. </album>

Line 23 encloses the album node.

3.1.2 Unselected Album Items
When an album is not selected in Helium, the summary uses the noalbum.xsl document to display that no album is selected. This document has no matching XML structure.

3.2 File Documents
File documents are used when one or more files are selected in the track list.

3.2.1 No Selected Files
The document nofiles.xsl will be used for rendering when no files are selected. This document is similar to the noalbum.xsl document and has no matching XML structure.

3.2.2 One Selected File
When one file is selected in the tracklist, the document summary.xsl will be used for rendering. This documents matching XML data structure is exactly the same as for Now Playing documents except that Suggested Tracks, Favourite Tracks, Albums By Artist and

Current album is omitted from the document. Instead of these nodes a new root node is available directly under the <EARData> node. This node is named <playing-history> and contains a list of date/timestamps when the selected track has been replayed, sorted in descending order. Please node that this root node is optional and will not exist if the track has never been replayed. The node will look like this:
1. 2. 3. 4. 5. 6. <playing-history> <entry value="2005-05-09 <entry value="2005-05-09 <entry value="2005-05-12 <entry value="2005-06-22 </playing-history> 15:51:10"/> 20:29:51"/> 18:24:03"/> 21:23:20"/>

The other available nodes and their data are described in the following sections: • 2.6 – File Data • 2.7 – Tag Data

3.2.3 Multiple Selected Files
When multiple files are selected in the tracklist, the document summarymulti.xsl will be used for rendering. The XML data document used for this summary type looks like this:
1. <?xml version="1.0" encoding="ISO-8859-1"?> 2. <fields> 3. <field name="NumberOfFiles" content="7"/> 4. <field name="TotalSize" content="78058133"/> 5. <field name="TotalLength" content="00:49:16"/> 6. <field name="AvgBitrate" content="210"/> 7. <field name="AvgSize" content="11151161"/> 8. <field name="AvgSize" content="11151161"/> 9. <field name="AvgLength" content="00:07:02"/> 10. <field name="AvgRating" content="0,64"/> 11. </fields>

Lines 3-10 defines the available data nodes. All sizes are expressed in bytes.

4. General Tips
• • Use the available helper classes; they contain the necessary functions for extracting data from the XML documents. Split visual & logic information by using a visual include file.

Sign up to vote on this title
UsefulNot useful