media-player-controller
Spawn media player app and control playback. Also allows reading player state through socket or web connection.
Supported Media Players
Player | Linux | Win | MacOS |
---|---|---|---|
mpv | yes | no | ? |
vlc | yes | yes | ? |
? - untested (feedback is welcome)
Player config
var player = app: 'mpv' // Media player name to use (mpv/vlc) args: // Player command line args (array of strings) cwd: null // Current working dir for media player spawn media: '/path/to/video.mp4' // Media to load on player launch (required) ipcPath: '/tmp/media-ctl-socket' // Path to socket connection file (mpv only) httpPort: 9280 // HTTP port for local communication (vlc only) httpPass: null // HTTP login password (vlc only, defaults to player name) detached: false // Spawn player as detached process;
Player functions
Each playback controlling function have an optional callback with eventual error
.
They are executed asynchronously by default and can be used after playback-started
event.
// Launch media player // Stop media player process // Resume playback // Pause playback // Cycle play/pause // Load new media file (without closing player) // Seek to position (value in seconds) // Adjust player volume (value 0-100) // Adjust playback speed (normal: 1.0) // Repeat playback (true or false) // Switch active video track // Switch active audio track // Switch active subtitle track // Add subtitles to currently playing video // Enable or disable fullscreen (true or false) // Toggle fullscreen on/off // Keep player open after playback (true or false) // Custom command for IPC/HTTP (array of args)
Please note that some commands are not yet implemented for every player (most of them are). If a command is not available for currently used player, callback will return error with a message saying so.
Available events
// Emited on media player app launch // Playback started and player can now be controlled // Data object with current playback event // Exit code emited on media player app close
Usage Example
const PlayerController = ; var player = app: 'mpv' args: '--fullscreen' media: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'; player; player; player; player;
Donation
If you like my work please support it by buying me a cup of coffee :-)