https://github.com/moosync/mediacontroller
NodeJS native module to handle MPRIS and WinRT implementation for media controls
https://github.com/moosync/mediacontroller
Last synced: 8 months ago
JSON representation
NodeJS native module to handle MPRIS and WinRT implementation for media controls
- Host: GitHub
- URL: https://github.com/moosync/mediacontroller
- Owner: Moosync
- License: gpl-3.0
- Created: 2022-07-19T17:30:05.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-10-31T01:54:09.000Z (over 2 years ago)
- Last Synced: 2025-01-17T16:17:15.972Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 88.9 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```bash
yarn add https://github.com/Moosync/MediaController.git
```
### Create a player
```js
const mediaController = require('media-controller')
mediaController.createPlayer('my player')
```
## Methods
#### updatePlayerDetails
To set media info to controls, use
```js
mediaController.updatePlayerDetails({
title: 'End of Time',
albumName: 'End of Time',
artistName: 'Alan Walker, Ahrix, K-391',
genres: ['Electronic'],
thumbnail: ''
})
```
#### setButtonStatus
You can set the status of buttons available
```js
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](./src/constsnts.js)
```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
```js
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)
```js
mediaController.setCurrentDuration(80) // In seconds
```