Skip to main content

Overview

Playback commands handle launching external players (MPV, VLC) and managing playback sessions with progress tracking.

Commands

play_media

Launch MPV player with a media item, including cloud streaming support.
#[tauri::command]
async fn play_with_mpv(
    window: Window,
    state: State<'_, AppState>,
    media_id: i64,
    resume: bool,
) -> Result<ApiResponse, String>
media_id
number
required
Database ID of the media item to play
resume
boolean
required
Whether to resume from saved position
ApiResponse
object
Cloud Streaming: For cloud files, this command:
  1. Fetches a temporary streaming URL from Google Drive
  2. Passes the URL and OAuth token to MPV via --http-header-fields
  3. Optionally enables disk caching for smoother playback
MPV is launched with IPC (named pipe on Windows) for real-time progress tracking. Progress is saved every 2 seconds and on quit.

play_with_vlc

Launch VLC player with a local media file.
#[tauri::command]
async fn play_with_vlc(
    state: State<'_, AppState>,
    media_id: i64,
    resume: bool,
) -> Result<ApiResponse, String>
media_id
number
required
Media item ID
resume
boolean
required
Whether to start at saved position
VLC does not support authenticated cloud streaming. Use MPV or the built-in player for cloud files.

update_resume_position

See Library Management - update_resume_position

get_active_mpv_sessions

Get all currently running MPV playback sessions.
#[tauri::command]
async fn get_active_mpv_sessions(
    state: State<'_, AppState>,
) -> Result<Vec<MpvSession>, String>
MpvSession[]
array
Array of active MPV sessions

kill_mpv_session

Terminate a specific MPV playback session.
Not directly exposed as a Tauri command. Use OS process management or wait for natural termination.

mpv_seek

Seek to a specific position in MPV playback.
Direct MPV IPC control is handled internally. For Watch Together sync, use wt_send_mpv_command instead.

mpv_set_pause

Pause or resume MPV playback.
Controlled via MPV’s IPC interface. See Watch Together commands for synchronized playback control.

get_stream_info

Get streaming URL for built-in player.
#[tauri::command]
async fn get_stream_info(
    state: State<'_, AppState>,
    media_id: i64,
) -> Result<StreamInfo, String>
media_id
number
required
Media item to stream
StreamInfo
object
Cloud streaming URLs are temporary (expire in 1 hour). Access tokens must be included in the Authorization header for video requests.

Events

mpv-playback-ended

Emitted when MPV playback finishes.
import { listen } from '@tauri-apps/api/event';

const unlisten = await listen<{
  media_id: number;
  title: string;
  season_number?: number;
  episode_number?: number;
  media_type: string;
  final_position: number;
  final_duration: number;
  completed: boolean;
}>('mpv-playback-ended', (event) => {
  if (event.payload.completed) {
    console.log(`Finished watching: ${event.payload.title}`);
  }
});
payload
object

Build docs developers (and LLMs) love