Skip to content

Latest commit

 

History

History
72 lines (61 loc) · 1.75 KB

README.md

File metadata and controls

72 lines (61 loc) · 1.75 KB

MediaController

This package provides a simple way to control MPRIS (Linux) and Windows system media controls (using WinRT).

Works with Electron

How to use

Install the package

yarn add https://github.com/Moosync/MediaController.git 

Create a player

const mediaController = require('media-controller')
mediaController.createPlayer('my player')

Methods

updatePlayerDetails

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>'
})

setButtonStatus

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"
})

setButtonPressCallback

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
  }
})

setPlaybackStatus

Set the playback status of player to Playing, Paused, Stopped, Changing or Closed

const PlaybackStateEnum = require('media-controller').PlaybackStateEnum
mediaController.setPlaybackStatus(PlaybackStateEnum.Playing)

setCurrentDuration (Linux only)

Set the current duration of player. (Useful when the user manually seeks and the duration is to be updated)

mediaController.setCurrentDuration(80) // In seconds