Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active December 17, 2025 03:23
Show Gist options
  • Select an option

  • Save jasonm23/b81662dfa7708270dd1ed42f43a24d9b to your computer and use it in GitHub Desktop.

Select an option

Save jasonm23/b81662dfa7708270dd1ed42f43a24d9b to your computer and use it in GitHub Desktop.
Electron spawning mpv as a standalone launched windows app

Running MPV from Electron / Windows

Tested on Windows 11 / mpv.exe is in user path.

Abstract

Running mpv via Electron on Windows, assuming the goal is to run MPV as a standalone so the Electron app can close without affecting mpv.

As opposed to exec, we use spawn as the method to fork the process, spawn returns a stream of io, in this example, we 'ignore' stdio.

We place in the main.js

import { ipcMain } from 'electron';
import { spawn } from 'child-process';

ipcMain.on('open-in-mpv', (_, path) => {
  spawn('mpv', [path], {
    shell: true,
    stdio: 'ignore',
    windowsHide: true,
  });
});

in preload.js:

const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('electronAPI', {
  openInMpv: (path) => ipcRenderer.send('open-in-mpv', path)
})

In the web/render side (windows as any).electronAPI.openInMpv(path: string) is the simplest call to electronAPI in TypeScript.

Notes

  • detaached appears very plausible on reading the docs, however in testing on Electron app installed on Windows windowsHide and detached do not work together. detached appears to take precident and launches mpv via a new terminal window.
  • windowsHide is windows specific so developer must set up platform specific spawn options if goal is multi platform build / deploy.
  • tl;dr detached and windowsHide are mutually exclusive. (detached will override windowsHide)

Follow up

There will be updates to this gist when (if) I need a Linux or MacOS desktop app for this or similar projects spawning mpv

Should broadly apply to any .exe mpv is used here in the tests, so no claims are made to avoid assumptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment