Yet Another Media Player (YAMP)

repository·main·Indexed 41 days ago

https://github.com/jianyu-li/yet-another-media-player

A feature-rich Home Assistant media card for controlling multiple media entities, managing Music Assistant queues, and customizing layouts and gestures. Version 2026.9.0 supports multi-player control, adaptive visual theming, and extensive YAML configuration for entities, search settings, and custom action chips.

Tokens
27.9K
Snippets
68
Records
115
Agent score
52%

What's inside YAMP

  1. Overview of YAMP features

    main

    Yet Another Media Player (YAMP) is a Home Assistant media card designed for controlling multiple media entities. Key capabilities include:

    • Multi-Player Control: Switch between players using chips and control volume individually or as a group.
    • Quick Grouping: Double-click a player chip to enter a mode for quickly joining or unjoining entities from the active group.
    • Gesture Controls: Use tap, double-tap, hold, or swipe on artwork to trigger actions like skipping tracks, play/pause, volume adjustment, or custom scripts.
    • Music Assistant & mass_queue: Full search and queue management, including synced lyrics support when used with the mass_queue integration.
    • Customization: Supports adaptive visual theming (artwork scaling), multiple layouts (collapsed or compact), and custom idle mode backgrounds (local files, URLs, or slideshows).
    • Extensibility: Add custom action chips or menu items that call Home Assistant actions/scripts, and use templates for dynamic configuration of volume, Music Assistant entities, and artwork overrides.
  2. Understand the YAMP Architecture and Subsystems

    main

    Yet Another Media Player (YAMP) is organized into several functional subsystems. Understanding these helps in identifying which parts of the codebase or configuration affect specific UI elements:

    • Card Orchestration: Managed by yet-another-media-player.js, this is the main entry point that handles state, subscriptions, and layout.
    • Configuration: Uses config-schema.js to define defaults (CARD_CONFIG_DEFAULTS), presets (TEMPLATE_CONFIGS), and normalization logic.
    • Template Engine: Supports both Jinja2 (via Home Assistant WebSocket subscriptions) and JavaScript (using [[[ ... ]]] syntax).
    • Media Controls: Includes specialized components for Player Chips/Tabs (chip-row.js), Playback/Volume (controls-row.js, volume-row.js), and Progress (progress-bar.js).
    • Search & Discovery: Handled by search-sheet.js for standalone or embedded search functionality.
    • Lyrics: Uses lyrics-view.js and lyrics-parser.js for synchronized LRC parsing and auto-scrolling.
    • Queue Management: Uses yamp-queue-drag.js and yamp-sortable.js for virtualized lists and drag-and-drop reordering.
  3. How template resolution works in YAMP

    main

    YAMP uses a dual-engine approach to resolve dynamic values in configuration fields. When a field is configured with a template, the engine determines the type based on the syntax used:

    1. JavaScript Templates: Identified by the [[[ ... ]]] syntax. These are evaluated client-side via _evaluateJsTemplate and the result is stored in a resolve cache.
    2. Jinja2 Templates: Identified by {{ ... }} or {% ... %} markers. These are resolved by subscribing to the Home Assistant render_template WebSocket service. The card updates when the server-side template value changes.

    Once resolved, the value is cached and the card re-renders with the new data.

  4. How template syntaxes work in YAMP

    main

    YAMP supports two distinct template engines for dynamic configuration. Both syntaxes have access to standard Home Assistant template functions (like states(), is_state()) and YAMP-specific variables.

    1. Jinja2 (Server-Side): Uses standard Home Assistant syntax {{ ... }} or {% ... %}. It is evaluated on the Home Assistant backend and requires an active WebSocket connection. It has access to the full Home Assistant state machine.
    2. JavaScript (Client-Side): Evaluated directly in your browser using triple brackets [[[ ... ]]]. This is extremely fast and ideal for restricted devices (like older iPads) where backend WebSocket template subscriptions might be blocked.
  5. How artwork and metadata resolution works

    main

    YAMP follows a specific priority and validation logic to ensure metadata accuracy:

    1. Preferred Source: If prefer_ma_metadata is enabled, the card prioritizes metadata (title, artist, artwork) from the linked Music Assistant entity.
    2. Fallback Validation: If falling back from a preferred source to the physical playback entity, the media_title must match exactly. If the titles differ, the fallback is blocked to prevent displaying stale or incorrect artwork.
    3. Idle State: If show_idle_artwork_when_not_playing is set to true, the card will display the configured idle artwork for a specific chip when its associated entity is not actively playing.
  6. Enhance Queue Controls with mass_queue

    main

    By installing the mass_queue community integration (droans/mass_queue), YAMP unlocks advanced queue management features within the Search sheet.

    Enabled Features:

    • Queue Browsing: Fetching the upcoming queue and browsing playlist tracks.
    • Queue Reordering: Drag-and-drop reordering of items in the upcoming queue list. YAMP optimizes the movement by calculating the most efficient sequence of move_up, move_down, or move_next calls.
    • Queue Management: Moving items (up, down, next) and removing items from the queue.
    • Playlist Management: Enables the Add to Playlist action in search results (automatically filters for editable playlists).
  7. Sync Multiple YAMP Cards using Helpers

    main

    You can keep two YAMP instances in sync (e.g., a main card and a dedicated search card) by using an input_text helper and two specific action types:

    1. sync_selected_entity: Writes the currently selected entity ID to the helper. Set in_menu: hidden so it runs in the background.
    2. select_entity: Monitors the helper and automatically switches the card's active chip to match the helper's value.

    Both actions require sync_entity_helper and sync_entity_type: yamp_playback_entity.

    # On both cards:
    actions:
      - action: sync_selected_entity
        in_menu: hidden
        sync_entity_type: yamp_playback_entity
        sync_entity_helper: input_text.current_yamp_entity
      - action: select_entity
        in_menu: hidden
        sync_entity_type: yamp_playback_entity
        sync_entity_helper: input_text.current_yamp_entity
  8. Manage grouped players

    main

    If entities are compatible, you can group them via the hamburger menu using "Group Players".

    • Grouped entities: Volume increases/decreases proportionately with the main entity.
    • Individual control: Use the Grouped Players menu to adjust individual player volumes or sync the group volume to the main entity.
    • Quick Grouping Mode: Double-click any entity chip to enter this mode.
      • Star Icon: Indicates the master player.
      • Plus (+): Join the active group.
      • Minus (-): Remove from the active group.
      • Exit: Double-click/tap any chip again.
    • Persistence: Use always_show_quick_group: true to keep this mode active by default.
  9. Implementation rules for templates and UI

    main

    When extending or working with YAMP, follow these core rules:

    • Dual-Engine Support: Any field that supports templating must be able to handle both Jinja2 ({{, {%) and JavaScript ([[[) markers.
    • Editor Visibility: In the configuration editor, if a setting is unavailable due to a conflicting option, it should be rendered as disabled (.disabled=${true}) rather than being hidden from the user.
    • Search Consistency: All search result items should be rendered using the renderSearchResultItem method in src/search-sheet.js to ensure a consistent look and feel across different search contexts.
  10. Search and Enqueue Actions

    main

    When searching, you can access enqueue strategies via the 3-dot menu (dots-vertical) on any search result:

    • Replace: Clears the current queue and plays the selection immediately.
    • Next: Adds the selection to the queue immediately after the currently playing track.
    • Replace Next: Replaces all upcoming items in the queue with the selection, starting after the current track.
    • Add to Queue: Adds the selection to the very end of the queue.
  11. Customize Lyrics and Details with Card Mod

    main

    If the built-in adaptive text doesn't meet your needs, you can use card-mod to apply custom CSS.

    To increase font size for the details row (for cards shorter than 300px), target the .details class. To style the lyrics view, use the provided CSS variables.

    card_mod:
      style: |
        .details {
          font-size: 2.4em !important;
        }
        .details .title {
          font-size: 1.6em !important;
        }
        .details .artist {
          font-size: 1.2em !important;
        }