Music service API
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.
| Method | Volumio calls it | Required |
|---|---|---|
handleBrowseUri(uri) | When the user opens a page of the plugin in Browse | Yes |
explodeUri(uri) | When the user plays or queues an item, or adds it to Favourites | Yes |
search(query) | When the user searches | No |
prefetch(track) | Near the end of a track, when the next one in the queue is from the same plugin | No |
clearAddPlayTrack(track), stop(), pause(), resume(), seek(ms) | When the user controls a track the plugin plays by itself | Only 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).
| Field | Value |
|---|---|
name | The name shown in Browse |
uri | The plugin's root URI, music_service/<id> |
plugin_type | music_service |
plugin_name | The 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' },
],
},
],
},
}
| Field | Value |
|---|---|
navigation.prev.uri | Where the back button goes. / is the Browse home. |
navigation.lists | One or more lists, shown one under the other |
lists[].title | Optional. The list's heading |
lists[].availableListViews | list, grid or both |
lists[].items | The items. See Item. |
Item
An entry of a Browse list or of a search result.
| Field | Value |
|---|---|
service | The plugin's id |
type | What the item is. See the table below. |
title | The main line |
artist, album | Optional. The second line |
albumart | Optional. The URL of an image |
icon | Optional. A Font Awesome class, such as fa fa-music, shown when there is no albumart |
uri | The item's URI, under music_service/<id> |
type | Selecting it | Item menu |
|---|---|---|
folder | Opens a page: Volumio calls handleBrowseUri with the item's uri | Yes |
playlist | Opens a page, like folder | Yes |
song | Plays the item: Volumio calls explodeUri with its uri | Yes |
webradio | Plays the item as a radio station | Yes |
item-no-menu | Opens a page, like folder | No |
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',
},
]
| Field | Value |
|---|---|
service | mpd to hand the stream to MPD. The plugin's id when the plugin plays the track itself. |
type | track |
uri | With service: 'mpd', the stream URL. Otherwise, the plugin's own URI for the track. |
name, title | The track title |
artist, album, albumart | Optional. 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.
search
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 */ ],
}
searchnever rejects and never throws. Volumio searches every source together, and one failure can lose the whole result. On an error, log it and resolvenull.- 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
searchmakes.
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:
| Method | Volumio 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>'):
| Field | Value |
|---|---|
status | play, pause or stop |
service | The plugin's id |
title, artist, album, albumart, uri | The track that plays |
seek | The position, in milliseconds |
duration | The track's length, in seconds |
samplerate, bitdepth, channels, bitrate | Optional. The audio format, shown to the user |
trackType | Optional. The format's name, such as flac |