Once you’ve determined whether to use a one-button or two-button implementation and created your ratings artwork, you can set up your presentation map. Use the samples below as starting points and customize them for your implementation.
SMAPI uses a PresentationMap
element as well as Match
elements and the Rating
sub-element to determine the rating icon to display for an item. Match
elements are also used with MenuItemOverrides
in Add actions, imageSizeMap
in Add album art, browseIconSizeMap
in Add browse icons, and SearchCategories
in Add search.
The sections below describe the PresentationMap
, Match
, and Rating
elements in detail.
Presentation Map
The presentation map for ratings must be the NowPlayingRatings
type:
1 2 3 |
<PresentationMap type="NowPlayingRatings"> ... </PresentationMap> |
Set trackEnabled
to true
to enable ratings for on demand tracks. Set programEnabled
to true
to enable ratings for programmed radio. For example, to enable ratings for on demand only, set trackEnabled
to true
and programEnabled
to false
, as shown below.
1 2 3 |
<PresentationMap type="NowPlayingRatings" trackEnabled="true" programEnabled="false"> ... </PresentationMap> |
See the Presentation Map Elements table for details.
Match element
The propname
attribute in the Match
element identifies the rating functionality. If you change the propname
, be sure to use the same name for each Match
element in your ratings implementation.
The value
attribute in the Match
element identifies the property value. All possible rating combinations should be assigned a unique property value, for example:
1 2 3 4 5 6 |
<Match propname="isStarred" value="0"> ... </Match> <Match propname="isStarred" value="1"> ... </Match> |
Sonos apps use the propname
and value
attributes of the Match
element to set the rating for an item. The getExtendedMetadataResponse
and getMetadataResponse
responses return these values in the mediaMetadata
element. See Develop ratings for details.
The Match
tag determines the state of the rating. So, for example, you could have a one star rating that cycles through five different states, with different color icons, by adding five Match
tags and the appropriate sub-elements.
Rating Element
The Rating
element represents an icon along with its state. It includes Icon
sub-elements with URLs to the images used on the Now Playing view of each app to show the rating.
1 2 3 4 5 6 7 |
<Rating Id="1"> <Icon Controller="acr" LastModified="00:00:00 1 Jan 1970" Uri=" http://sonos-img.ws.sonos.com/thumbs-up-unselected.svg" /> ... </Rating> |
Each Rating
element has an Id
attribute that must be an integer unique to the property name. The Sonos app sends this Id
to your service when a user rates an item. See Develop ratings for details.
You must provide rating icons for every Sonos app listed in the Controller
attribute section of the Presentation Map Elements table. Therefore, each Rating
element must include one Icon
sub-element per Controller
. acr
, acr-hdpi
, icr
, pcdcr
, macdcr
, and cr200
icons should be PNGs. The universal icon must be an SVG. Be sure to use the correct size icons for each icon as specified in the guidelines. See the Use rating icons for details about the required files and file formats.
If you change the icon or update it in any way, you must also update the LastModified
attribute to force the Sonos app to re-load the image from its origin. Otherwise, the app will continue to use the image previously downloaded and stored in its local cache.
The order of the ratings in these match values matter. In a two button implementation, the Sonos app displays the first rating in the presentation map on the left side of the app. The app displays the next rating to the right. Be sure to use the same order for the icons in each match tag.
If you do not require details about which icon was pressed, you could simplify your implementation to only note whether the returned value of the Rating
Id
is even or odd, and act accordingly. In the example below, all thumbs up actions are odd, and all thumbs down actions are even.
No rating implementation
If you don’t want to offer ratings for your service, simply do not include a presentation map section with a NowPlayingRatings
type.
One-button Rating implementation
We’ve configured the presentation map in this section for a one-button rating implementation with two states, starred or unstarred. To offer a one-button rating implementation, copy the presentation map below and customize it for your service.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<PresentationMap type="NowPlayingRatings" trackEnabled="true" programEnabled="false"> <Match propname="isStarred" value="0"> <!-- the track is unstarred; the action is to star --> <Ratings> <Rating Id="1" AutoSkip="NEVER" OnSuccessStringId="STAR_SUCCESS" StringId="STAR"> <Icon Controller="acr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="acr-hdpi" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="icr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="pcdcr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="macdcr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="cr200" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-unselected.png" /> <Icon Controller="universal" LastModified="00:00:00 1 Jan 1970" Uri="http://sonos-img.ws.sonos.com/star-unselected.svg" /> </Rating> </Ratings> </Match> <Match propname="isStarred" value="1"> <!-- the track is starred; the action is to unstar --> <Ratings> <Rating Id="0" AutoSkip="NEVER" OnSuccessStringId="UNSTAR_SUCCESS" StringId="UNSTAR"> <Icon Controller="acr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="acr-hdpi" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="icr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="pcdcr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="macdcr" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="cr200" LastModified="00:00:00 1 Jan 1970" Uri="http://<URL>/star-selected.png" /> <Icon Controller="universal" LastModified="00:00:00 1 Jan 1970" Uri="http://sonos-img.ws.sonos.com/star-selected.svg" /> </Rating> </Ratings> </Match> </PresentationMap> |
Two-button Rating Implementation
We’ve configured the presentation map in this section for a two-button rating implementation with two icons each with two states, selected or unselected. To offer a two-button rating implementation, copy the presentation map below and customize it for your service.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
<PresentationMap type="NowPlayingRatings"> <Match propname="vote" value="0"> <!-- the track is unrated --> <Ratings> <Rating AutoSkip="ALWAYS" Id="0" StringId="VoteDown" OnSuccessStringId="VoteDownSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-down-unselected.svg"/> </Rating> <Rating AutoSkip="NEVER" Id="1" StringId="VoteUp" OnSuccessStringId="VoteUpSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="100:00:00 31 Dec 2014" Uri="<URL>/vote-up-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-up-unselected.svg"/> </Rating> </Ratings> </Match> <Match propname="vote" value="1"> <!-- the track is rated thumbs up --> <Ratings> <Rating AutoSkip="ALWAYS" Id="2" StringId="VoteDown" OnSuccessStringId="VoteDownSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-down-unselected.svg"/> </Rating> <Rating AutoSkip="NEVER" Id="3" StringId="VoteUp" OnSuccessStringId="VoteUpSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up_active-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-up-selected.svg"/> </Rating> </Ratings> </Match> <Match propname="vote" value="2"> <!-- the track is rated thumbs down --> <Ratings> <Rating AutoSkip="ALWAYS" Id="4" StringId="VoteDown" OnSuccessStringId="VoteDownSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-down_active-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-down-selected.svg"/> </Rating> <Rating AutoSkip="NEVER" Id="5" StringId="VoteUp" OnSuccessStringId="VoteUpSuccess"> <Icon Controller="icr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-52x52.png"/> <Icon Controller="acr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-52x52.png"/> <Icon Controller="acr-hdpi" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-80x80.png"/> <Icon Controller="macdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-40x32.png"/> <Icon Controller="pcdcr" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-40x32.png"/> <Icon Controller="cr200" LastModified="00:00:00 31 Dec 2014" Uri="<URL>/vote-up-66x66.png"/> <Icon Controller="universal" LastModified="00:00:00 31 Dec 2014" Uri="http://sonos-img.ws.sonos.com/thumbs-up-unselected.svg"/> </Rating> </Ratings> </Match> </PresentationMap> |
Presentation Map Elements
The table below describes the elements and attributes for a Ratings presentation map. The PresentationMap
tag should have the following attributes:
Name | Type | Description |
---|---|---|
type |
String | This must be set to NowPlayingRatings . |
trackEnabled |
Boolean | Set to true if ratings should be enabled for tracks. Use this for On Demand music. |
programEnabled |
Boolean | Set to true if ratings should be enabled for Programmed Radio. |
An Icon
has the following attributes:
Name | Type | Description |
Controller |
Enumeration | There must be one Icon tag for each of the following:
|
LastModified |
Date | This is a date string in the format 10:29:20 17 Aug 2011 . This date must be updated any time the icons change even if the icon URL has changed as well. |
Uri |
string | The URI to the location of the icon image. For all but the universal controller, the image must be in the PNG file format and should support transparency. The universal controller must be in the SVG file format. The 36×36 pixel icon should be used for the icr and acr controller types; the 54×54 pixel icon should be used for the acr-hdpi ; the 44×44 pixel icon should be used for the CR200 controller; the 21×21 pixel icon should be used for the desktop controllers. See the Use rating icons for details. |
A Rating
has the following attributes:
Name | Type | Description |
AutoSkip |
Enumeration | This defines whether or not this track should be skipped when a listener clicks this rating icon. This is useful for a thumbs down or ban rating where the user has indicated that they don’t like the track. Must be one of the following values: ASK , ALWAYS or NEVER . |
Id |
int | This is the value that will be passed to the rateItem method. The Id must be unique for the given property name. |
OnSuccessStringId |
string(128) | This is the ID of the String that will be displayed if the rateItem call is successful after clicking the icon. If you add this attribute, it must correlate with a String Id in the Strings XML file. See Configure ratings for details. |
State |
Enumeration | The state of the rating. Must be one of the following values: DEFAULT , RATED , UNRATED . Currently, DEFAULT acts the same as UNRATED . |
StringId |
string(128) | This is the ID of the string that will be displayed on MouseOver of the Rating Icon. If you add this attribute, it must correlate with a String Id in the Strings XML file. See Configure ratings for details. |
Type |
Enumeration | The type of rating for the Sonos app to display. Must be one of the following: STAR , THUMBSUP , THUMBSDOWN , LOVE , HATE , BAN . |
Strings
If you’re not familiar with Strings XML, read Strings and localization before you continue.
Continuing with the ratings implementation, we will now add two string messages, each with a stringId
for every Rating
tag:
stringId
: displayed when mouse is hovered over the Rating icon;OnSuccessStringId
: when the call associated with the Rating icon (rateItem
) is successful.
We will add the following to our Strings XML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<stringtables xmlns="http://sonos.com/sonosapi"> <stringtable rev="1" xml:lang="en-US"> <string stringId="STAR">Star track</string> <string stringId="UNSTAR">Un-star track</string> <string stringId="STAR_SUCCESS">Track starred successfully</string> <string stringId="UNSTAR_SUCCESS">Track un-starred successfully</string> </stringtable> <stringtable rev="1" xml:lang="da-DK"> <string stringId="STAR">Stjernemarkér nummer</string> <string stringId="UNSTAR">Fjern stjernemarkering</string> <string stringId="STAR_SUCCESS">Nummeret er stjernemarkere</string> <string stringId="UNSTAR_SUCCESS">Stjernemarkeringen er fjernet</string> </stringtable> <stringtable rev="1" xml:lang="da-DK"> ... </stringtables> |