RetroPlayer
By Mats Eirik Hansen

RetroPlayer API

The RetroPlayer API is available to JavaScript through the RetroPlayer variable. This variable is bound to an object that has properties with information from RetroPlayer and methods for controlling RetroPlayer.

Note: The values of the properties of the RetroPlayer object are not valid until after the HTML document is loaded and the load event has been fired. Typically a custom windows or visualizer will add observers using RetroPlayer.addPropertyObserver() to the properties it wants to display so that the display is updated when the property values are updated.

RetroPlayer object

Properties

appearance The current macOS appearance for the window. The value is a string and the possible values are dependent on the version of macOS but typically values are "NSAppearanceNameAqua" for light mode and "NSAppearanceNameDarkAqua" for dark mode.
currentSong The song currently being played. The value is an object with the following properties:
playQueue A PlayQueue object with the current state of the play queue.
position The current position in the current song. The value is the number of seconds into the current song as a a floating point number. This value is not automatically updated so a custom window implementation should call updateProperties() at a suitable rate.
repeat The current repeat mode of RetroPlayer. The value is a string and the possible values are "off" for no repeat, "song" for repeating the current song and "all" for repeating all songs in the play queue.
shuffleEnabled True will shuffle the play queue and false will restore the play queue to the order that the songs were added.
state The current playback state. The value is a string and the possible values are "playing", "paused" and "stopped".
userDefaults The user defaults database for the custom window or visualizer. It can be observed with addPropertyObserver() but is generally not accessed directly. Instead getUserDefault() and setUserDefault() is used.

Methods

addPropertyObserver(propertyName, observer) Add an observer to the named property. The observer must be a function an it will be called with the new property value as a parameter whenever the property value changes.
adjustWindowSizeToContent() Adjust the window size so that content fits in the window. The size of the content is found by computing the size of the BODY element.
createAnalyser() Create an AnalyserNode for doing time and frequency domain analysis of the audio output from RetroPlayer. It is mostly compatible with the AnalyserNode interface defined by the Web Audio API. The difference is that it is always connected and only support the methods and properties defined by AnalyserNode and not what it inherits from AudioNode.
getElementContentSize(element) Get the size of the content of an element.
getElementOuterSize(element) Get the outer size of an element.
getLocalizedString(string, localizedStrings) Get a localized string based on the current language. The caller must provide localized strings as a dictionary object where the language identifier is the key and the value is a new dictionary where the original string is the key and the value is the localized string. The language identifier is according to ISO 639-1, e.g. "en" for English and "nb" for Norwegian bokmål. localizedString = RetroPlayer.getLocalizedString("By", { "nb" : { "By" : "Av" } });
getUserDefault(key, defaultValue) Get the value for a single key in the user defaults database for the custom window or visualizer. The provided default value will be returned if no value has been set.
isKeyWindow() Returns true if the custom window or the window the visualizer is in is the current key window.
isMainWindow() Returns true if the custom window or the window the visualizer is in is the current main window.
isPlaying() Returns true if a song is playing.
pause() Pause song playing.
play() Start playing current song.
playNext() Start playing the next song in the play queue.
playPause () Toggle play/pause.
playPrevious() Start playing the previous song in the play queue.
removePropertyObserver(propertyName, observer) Remove an observer from the named property. The observer must be a function that has previously been added as an observer with addPropertyObserver().
setMaxPlayQueueSongCount(maxPlayQueueSongCount) Set the maximum number of songs to include in the songs property of the playQueue object.
setRepeat(repeat) Set the repeat property. "off" will disable repeat, "song" will repeat current song and "all" will repeat all songs in the play queue.
setShuffleEnabled(shuffleEnabled) Set the shuffleEnabled property. true will shuffle the play queue and false will restore the play queue to the order that the songs were added.
setUserDefault(key, value) Set the value for a single key in the user defaults database for the custom window or visualizer.
setUserDefaults(userDefaults) Set the user defaults database for the custom window or visualizer.
setWindowContentSize(width, height) Set the size of the content area of the window.
setWindowStyle(windowStyle) Set the CSS style to be used for the window. The style must be a CSSStyleDeclaration object. This function only affects custom windows and is called automatically when the window has loaded with the computed style for the HTML element.
updateProperties(propertyNames) Update the value of the named properties. Observers of properties that changes value will be called.

PlayQueue object

songCount The number of songs in the play queue.
songs An array of Song objects for the songs in the play queue. For performance reasons the length of this array is limited. By default the max length is 0 so a custom window or visualizer must call RetroPlayer.setMaxPlayQueueSongCount() to change the limit to get any songs at all.
hasNextSong True if the there is a next song in the play queue. This means that calling playNext() will have an effect. If this is not the case then the value will be false.
hasPreviousSong True if the there is a previous song in the play queue. This means that calling playPrevious() will have an effect. If this is not the case then the value will be false.

Song object

artist The creator of the song.
demoName The name of the demo the song was used in.
duration The duration of the song in seconds. This will be 0 if the duration of the song is not known.
gameName The name of the game the songs was used in.
groupName The name of the group the artist is/was a member of.
imageFilePath The path to the file with the image for the song.
name The name of the song.
releaseYear The release year of the song.
subsong The subsong number for songs that originates from a file with more than one song.