A moosync extension can be split into 3 parts

  • Lifecycle hooks
  • Methods
  • Events

Lifecycle hooks

There are 2 optional lifecycle hooks for an extension

  • onStarted
  • onStopped

onStarted

onStarted hook is invoked after moosync’s extension host has started or after the extension has been installed.
This method only signifies that your extension can now communicate with moosync.
It is recommended to initialize your custom code in this method.

onStopped

onStopped hook is invoked after moosync’s extension host has stopped or after the extension has been uninstalled.
It is recommended to destroy all objects and stop all tasks in this method.

Methods

Your extension is provided with a global constant api.
For typescript, this can be declared inside your declaration file

declare const api: import('@moosync/moosync-types').extensionAPI

api exposes some methods, namely:

Events

Events can be listened to using api.on(…)

List of events:

  • ‘requestedPlaylists’ *
  • ‘requestedPlaylistSongs’ *
  • ‘oauthCallback’
  • ‘songQueueChanged’
  • ‘seeked’
  • ‘volumeChanged’
  • ‘playerStateChanged’
  • ‘songChanged’
  • ‘preferenceChanged’
  • ‘playbackDetailsRequested’ *
  • ‘customRequest’ *
  • ‘requestedSongFromURL’ *
  • ‘requestedPlaylistFromURL’ *
  • ‘requestSearchResult’ *
  • ‘requestedRecommendations’ *
  • ‘requestedLyrics’ *

* These events require you to return some data from their callbacks

Documentation

Documentation for API and models can be found here

Examples

API examples can be found here