This package provides a simple way to control MPRIS (Linux) and Windows system media controls (using WinRT).
Works with Electron
yarn add https://github.com/Moosync/MediaController.git
const mediaController = require('media-controller')
mediaController.createPlayer('my player')
To set media info to controls, use
mediaController.updatePlayerDetails({
title: 'End of Time',
albumName: 'End of Time',
artistName: 'Alan Walker, Ahrix, K-391',
genres: ['Electronic'],
thumbnail: '<absolute_path_to_image>'
})
You can set the status of buttons available
mediaController.setButtonStatus({
play: true,
pause: true,
next: true,
prev: true,
seek: false,
shuffle: false,
loop: 'Track' // Possible values "None" | "Track" | "Playlist"
})
Callback to fire when a button is pressed on media controls. For button constants, see constants.js
const ButtonEnum = require('media-controller').ButtonEnum
mediaController.setButtonPressCallback((button) => {
if (button === ButtonEnum.Play) {
// handle play
} else if (button === ButtonEnum.Next) {
// handle next
}
})
Set the playback status of player to Playing, Paused, Stopped, Changing or Closed
const PlaybackStateEnum = require('media-controller').PlaybackStateEnum
mediaController.setPlaybackStatus(PlaybackStateEnum.Playing)
Set the current duration of player. (Useful when the user manually seeks and the duration is to be updated)
mediaController.setCurrentDuration(80) // In seconds