Tauri Plugin libmpv
A Tauri plugin for embedding the mpv player in your app via libmpv.
Prerequisites
Before installing the plugin, you need to gather the necessary dynamic libraries. This plugin requires two parts to work:
- The Wrapper Library:
libmpv-wrapper (Interface between plugin and libmpv).
- The Actual mpv Library:
libmpv (The video player core).
Windows Setup
- Download the Wrapper:
- Download libmpv:
- Project Setup:
- Create a folder named
lib inside your src-tauri directory.
- Copy both
libmpv-wrapper.dll and libmpv-2.dll into src-tauri/lib/.
Linux Setup (Debian/Ubuntu)
Installation
Install the Plugin
npm run tauri add libmpv
Configure Resources (Important)
You must configure Tauri to bundle the dynamic libraries (.dll or .so) with your application so they are available at runtime.
Modify src-tauri/tauri.conf.json
{
"bundle": {
"resources": [
"lib/**/*"
]
}
}
Configure Window Transparency
For mpv to properly embed into your Tauri window, you need to configure transparency:
Set window transparency in src-tauri/tauri.conf.json
{
"app": {
"windows": [
{
"title": "Your App",
"width": 1280,
"height": 720,
"transparent": true
}
]
}
}
Set web page background to transparent in your CSS
html,
body {
background: transparent;
}
Quick Start
import {
MpvObservableProperty,
MpvConfig,
init,
observeProperties,
command,
setProperty,
getProperty,
destroy,
} from 'tauri-plugin-libmpv-api'
const OBSERVED_PROPERTIES = [
['pause', 'flag'],
['time-pos', 'double', 'none'],
['duration', 'double', 'none'],
['filename', 'string', 'none'],
] as const satisfies MpvObservableProperty[]
const mpvConfig: MpvConfig = {
initialOptions: {
'vo': 'gpu-next',
'hwdec': 'auto-safe',
'keep-open': 'yes',
'force-window': 'yes',
},
observedProperties: OBSERVED_PROPERTIES,
}
try {
await init(mpvConfig)
console.log('mpv initialization completed successfully!')
} catch (error) {
console.error('mpv initialization failed:', error)
}
const unlisten = await observeProperties(
OBSERVED_PROPERTIES,
({ name, data }) => {
switch (name) {
case 'pause':
console.log('Playback paused state:', data)
break
case 'time-pos':
console.log('Current time position:', data)
break
case 'duration':
console.log('Duration:', data)
break
case 'filename':
console.log('Current playing file:', data)
break
}
})
await command('loadfile', ['/path/to/video.mp4'])
await setProperty('volume', 75)
const volume = await getProperty('volume', 'int64')
console.log('Current volume is:', volume)
Platform Support
| Windows | ✅ | Fully tested. Requires libmpv-2.dll and libmpv-wrapper.dll. |
| Linux | ⚠️ | Experimental. Window embedding is not working. Requires system libmpv and libmpv-wrapper.so. |
| macOS | ⚠️ | Not tested. |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MPL-2.0 License - see the LICENSE file for details.