No description
.gitignore | ||
mpv-mode.el | ||
README.md |
MPV Mode
mpv-mode
is an Emacs package that provides audio playback from YouTube URLs using mpv
. It allows you to play audio-only content directly from Emacs with simple pause/resume controls.
Features
- Play audio from YouTube URLs without video
- Interactive URL input via minibuffer
- Pause/resume playback with a single command
- Real-time progress indicator in mode line
- Automatic process management (new playback stops current one)
- Clean process cleanup and error handling
Architecture
Core Components
Process Management
- Single global process variable (
mpv-audio-process
) tracks the current mpv instance - Automatic cleanup when starting new playback or on errors
- Process state checking before operations
Interactive Functions
mpv-audio-play
: Prompts for URL and starts playbackmpv-audio-toggle
: Sends space character to mpv for pause/resumempv-audio-stop
: Explicitly stops current playback
Progress Tracking
- Real-time parsing of mpv output for progress information
- Process filter captures and parses progress lines
- Mode line integration shows current status:
♪ YT:abcd1234 95% [07:23/10:45]
Configuration
mpv-audio-executable
: Customizable path to mpv binary (defaults to "mpv")
Design Rationale
- Single Process: Simplicity over complexity - one audio stream at a time
- Auto-Stop Behavior: Starting new playback automatically replaces current one
- Direct Process Communication: Uses
process-send-string
for reliable keypress simulation - Real-time Progress: Process filter parsing over polling for efficient, immediate updates
- Mode Line Integration: Standard Emacs pattern for always-visible status information
- Error Handling: Graceful degradation with user-friendly messages
Installation
- Ensure
mpv
is installed on your system - Load the package in your Emacs configuration:
(load-file "/path/to/mpv-mode.el")
Usage
Basic Commands
-
Start Playback:
M-x mpv-audio-play
- Enter a YouTube URL when prompted
- Automatically stops any current playback
-
Pause/Resume:
M-x mpv-audio-toggle
- Toggles between pause and play states
-
Stop Playback:
M-x mpv-audio-stop
- Explicitly stops current audio playback
Example Workflow
M-x mpv-audio-play
- Enter:
https://www.youtube.com/watch?v=VIDEO_ID
- Audio starts playing, progress appears in mode line:
♪ YT:VIDEO_ID 15% [01:23/09:12]
M-x mpv-audio-toggle
to pauseM-x mpv-audio-toggle
to resumeM-x mpv-audio-play
with new URL to switch content
Progress Indicator
The mode line displays real-time playback information:
- ♪: Music note indicator
- YT:VIDEO_ID: Extracted video ID from YouTube URLs
- 95%: Current progress percentage
- [07:23/10:45]: Current time / Total duration
The indicator automatically appears when playback starts and disappears when stopped.
Configuration
Customize the mpv executable path if needed:
(setq mpv-audio-executable "/custom/path/to/mpv")
Requirements
- Emacs 24.3+
- mpv media player