Skip to main content

Music service API

BetaThe plugin SDK and these pages are new. They change with each release, as developers use them and tell us what works.View as Markdown

A plugin of type music_service answers Volumio's Browse, play and search requests. This page lists the methods Volumio calls and the objects they return. Every method returns a kew promise. Build a music service shows them in a working plugin.

MethodVolumio calls itRequired
handleBrowseUri(uri)When the user opens a page of the plugin in BrowseYes
explodeUri(uri)When the user plays or queues an item, or adds it to FavouritesYes
search(query)When the user searchesNo
prefetch(track)Near the end of a track, when the next one in the queue is from the same pluginNo
clearAddPlayTrack(track), stop(), pause(), resume(), seek(ms)When the user controls a track the plugin plays by itselfOnly for such a plugin

URIs​

Every URI the plugin hands to Volumio starts with music_service/<id>, such as music_service/my_service/album/42. Volumio sends a request to the first source whose URI starts the requested one. Its own sources come first: favourites, playlists, search, artists://, albums://, genres://, UPnP and radio. A root that is only the plugin's id can lose its pages to them.

Browse source​

The plugin's entry in Browse. Add it in onStart with this.commandRouter.volumioAddToBrowseSources(source), and remove it in onStop with volumioRemoveToBrowseSources(name).

FieldValue
nameThe name shown in Browse
uriThe plugin's root URI, music_service/<id>
plugin_typemusic_service
plugin_nameThe plugin's id

volumioUpdateToBrowseSources(name, source) changes an entry in place, such as after the user renames it.

handleBrowseUri​

Resolves the page to show for uri. Rejects when the plugin has no page for it.

{
navigation: {
prev: { uri: 'music_service/my_service' },
lists: [
{
title: 'Albums',
availableListViews: ['list', 'grid'],
items: [
{ service: 'my_service', type: 'folder', title: 'Kind of Blue', artist: 'Miles Davis', albumart: 'https://img.example.com/42.jpg', uri: 'music_service/my_service/album/42' },
],
},
],
},
}
FieldValue
navigation.prev.uriWhere the back button goes. / is the Browse home.
navigation.listsOne or more lists, shown one under the other
lists[].titleOptional. The list's heading
lists[].availableListViewslist, grid or both
lists[].itemsThe items. See Item.

Item​

An entry of a Browse list or of a search result.

FieldValue
serviceThe plugin's id
typeWhat the item is. See the table below.
titleThe main line
artist, albumOptional. The second line
albumartOptional. The URL of an image
iconOptional. A Font Awesome class, such as fa fa-music, shown when there is no albumart
uriThe item's URI, under music_service/<id>
typeSelecting itItem menu
folderOpens a page: Volumio calls handleBrowseUri with the item's uriYes
playlistOpens a page, like folderYes
songPlays the item: Volumio calls explodeUri with its uriYes
webradioPlays the item as a radio stationYes
item-no-menuOpens a page, like folderNo

The item menu holds actions such as play, add to queue and add to Favourites.

explodeUri​

Resolves the tracks a URI plays, as an array, even for one track. The queue adds every track, and Favourites reads the first. Rejects when nothing plays uri.

[
{
service: 'mpd',
type: 'track',
uri: 'https://stream.example.com/42/1.flac',
name: 'So What',
title: 'So What',
artist: 'Miles Davis',
album: 'Kind of Blue',
albumart: 'https://img.example.com/42.jpg',
},
]
FieldValue
servicempd to hand the stream to MPD. The plugin's id when the plugin plays the track itself.
typetrack
uriWith service: 'mpd', the stream URL. Otherwise, the plugin's own URI for the track.
name, titleThe track title
artist, album, albumartOptional. Shown while the track plays

With service: 'mpd', MPD plays the stream and handles pause, stop and seek. Use it whenever your service gives a stream URL.

Volumio calls search({ value }), where value is the text the user typed. It resolves null when nothing matches, or one list:

{
title: 'My Service',
availableListViews: ['list', 'grid'],
items: [ /* items, as in Browse */ ],
}
  • search never rejects and never throws. Volumio searches every source together, and one failure can lose the whole result. On an error, log it and resolve null.
  • When Volumio searches every source, it stops waiting for a plugin after 5 seconds. From the plugin's own Browse page, it waits as long as the plugin takes. Put a time limit on every request search makes.

prefetch​

Optional. Volumio calls prefetch(track) near the end of the current track, when the next track in the queue has the same service. track is that next track. Use it to prepare the next track, so playback continues without a gap.

Playback methods​

A plugin whose tracks have service: '<id>' plays them itself. It implements these methods, each returning a kew promise:

MethodVolumio calls it
clearAddPlayTrack(track)To play track
stop()When the user stops playback
pause()When the user pauses
resume()When the user resumes
seek(ms)When the user moves to a position, in milliseconds

The plugin reports every change of state with this.commandRouter.servicePushState(state, '<id>'):

FieldValue
statusplay, pause or stop
serviceThe plugin's id
title, artist, album, albumart, uriThe track that plays
seekThe position, in milliseconds
durationThe track's length, in seconds
samplerate, bitdepth, channels, bitrateOptional. The audio format, shown to the user
trackTypeOptional. The format's name, such as flac

Was this page helpful?