No description
Find a file
2025-09-16 12:42:16 +02:00
.gitignore Initial commit 2025-09-16 12:34:14 +02:00
mpv-mode.el Supposedly adds the progress to the status bar 2025-09-16 12:42:16 +02:00
README.md Supposedly adds the progress to the status bar 2025-09-16 12:42:16 +02:00

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 playback
  • mpv-audio-toggle: Sends space character to mpv for pause/resume
  • mpv-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

  1. Ensure mpv is installed on your system
  2. 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

  1. M-x mpv-audio-play
  2. Enter: https://www.youtube.com/watch?v=VIDEO_ID
  3. Audio starts playing, progress appears in mode line: ♪ YT:VIDEO_ID 15% [01:23/09:12]
  4. M-x mpv-audio-toggle to pause
  5. M-x mpv-audio-toggle to resume
  6. M-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