Skip to content

bilipp/SwiftMediaBar

Repository files navigation

SwiftMediaBar

A sleek macOS menu bar application that displays your currently playing media information right in your menu bar. SwiftMediaBar provides a clean, unobtrusive way to see what's playing across all your media applications.

SwiftMediaBar Demo Swift License

Features

  • Real-time Media Display: Shows currently playing song, artist, and album in your menu bar
  • Universal Compatibility: Works with Apple Music, Spotify, and other media applications
  • Album Artwork: Displays album artwork when available
  • Playback Status: Shows play/pause status and progress information
  • Clean Interface: Minimalist design that doesn't clutter your menu bar
  • Lightweight: Runs efficiently in the background with minimal resource usage
  • Auto-refresh: Updates every 5 seconds to keep information current

Screenshots

Media Playing

Media Playing

No Media Playing

No Media Playing

Menu Bar Display

The app shows a compact view of your current media in the menu bar:

♪ Artist Name - Song Title

Detailed Popover

Click the menu bar item to see detailed information including:

  • Album artwork
  • Full song title, artist, and album
  • Playback status
  • Additional metadata (genre, track number, source app)

Requirements

  • macOS: Compatible with all macOS versions including the latest macOS Sonoma
  • media-control: Version 0.7.2 (optional fallback dependency)
  • Xcode: 15.0 or later (for building from source)

How It Works

SwiftMediaBar intelligently retrieves your media information using a two-tier priority system to ensure both performance and compatibility:

  1. Native AppleScript (JXA): The app first attempts to fetch media information directly from Apple Music or Spotify using JavaScript for Automation (JXA). This is highly efficient and provides native integration without external dependencies.
  2. media-control Fallback: If the native approach fails (e.g., if neither Music nor Spotify is running, or if an error occurs), the app automatically falls back to the media-control command-line tool, providing broader support for other applications.

Installation

Option 1: Download Pre-built App (Recommended)

  1. Download the latest release from the Releases page
  2. Unzip the downloaded file
  3. Move SwiftMediaBar.app to your Applications folder

Option 2: Build from Source

  1. Clone this repository:

    git clone https://github.com/bilipp/SwiftMediaBar.git
    cd SwiftMediaBar
  2. Open the project in Xcode:

    open SwiftMediaBar.xcodeproj
  3. Build and run the project (⌘+R)

Optional Dependency: media-control

While SwiftMediaBar works out of the box for Apple Music and Spotify, installing media-control adds support for a wider range of applications as a secondary fallback:

brew install media-control

Usage

Getting Started

  1. Launch SwiftMediaBar from your Applications folder
  2. The app will appear in your menu bar with a musical note (♪) icon
  3. Start playing music in any supported application
  4. The menu bar will update to show your current media information

Menu Bar Display

  • No Media: Shows "♪" when nothing is playing
  • Loading: Shows "♪ Loading..." while fetching information
  • Playing: Shows "♪ Artist - Song Title" (truncated to fit)
  • Error: Shows "♪ Error" if there's an issue

Detailed View

Click the menu bar item to open a popover with detailed information:

  • Album artwork (when available)
  • Full song title, artist, and album names
  • Playback status (playing/paused)
  • Additional metadata like genre and track number
  • Source application information

Quitting the App

Click the menu bar item and select "Quit" from the popover.

Supported Applications

SwiftMediaBar works with any application that provides media information through macOS's Media Remote framework, including:

  • Apple Music
  • Spotify

Configuration

SwiftMediaBar works out of the box with minimal configuration needed. The app automatically:

  • Updates every 5 seconds
  • Truncates long titles to fit in the menu bar
  • Handles different media sources
  • Manages album artwork display

Customization Options

Currently, SwiftMediaBar focuses on simplicity and doesn't require configuration. Future versions may include:

  • Custom update intervals
  • Display format options
  • Menu bar text length preferences

Troubleshooting

Common Issues

"No Media Playing" when music is playing

Cause: The app may be failing to communicate with the active media player via AppleScript.

Solutions:

  1. Check if the media application (Music or Spotify) is running and playing.
  2. If using another application, ensure media-control is installed (brew install media-control) as it acts as the fallback mechanism.
  3. Test if media-control works manually:
    media-control get

"Error" message in menu bar

Cause: Permission issues or script execution problems.

Solutions:

  1. Ensure the app has necessary accessibility or automation permissions in System Settings > Privacy & Security.
  2. Restart SwiftMediaBar.
  3. If using an unsupported app, ensure media-control is installed.

App doesn't appear in menu bar

Cause: The app might have crashed or failed to launch properly.

Solutions:

  1. Check Activity Monitor for SwiftMediaBar process
  2. Try launching from Terminal to see error messages:
    /Applications/SwiftMediaBar.app/Contents/MacOS/SwiftMediaBar
  3. Restart your Mac if the issue persists

Outdated or incorrect media information

Cause: Caching or timing issues with media updates.

Solutions:

  1. Wait a few seconds for the next automatic update
  2. Restart SwiftMediaBar
  3. Check if the source media application is responding properly

Getting Help

If you encounter issues not covered here:

  1. Check the Issues page for similar problems
  2. Create a new issue with:
    • Your macOS version
    • media-control version (media-control --version)
    • Steps to reproduce the problem
    • Any error messages

Development

Project Structure

SwiftMediaBar/
├── SwiftMediaBar/
│   ├── SwiftMediaBarApp.swift      # Main app entry point
│   ├── Managers/
│   │   └── MenuBarManager.swift    # Menu bar management
│   ├── Services/
│   │   └── MediaService.swift      # Media information service
│   ├── Models/
│   │   └── MediaInfo.swift         # Media data model
│   └── Views/
│       └── MenuView.swift          # Popover UI
├── SwiftMediaBarTests/             # Unit tests
└── SwiftMediaBarUITests/           # UI tests

Key Components

  • MenuBarManager: Handles menu bar item creation and updates
  • MediaService: Interfaces with media-control to fetch media information
  • MediaInfo: Data model representing current media state
  • MenuView: SwiftUI view for the detailed popover interface

Building and Testing

  1. Open SwiftMediaBar.xcodeproj in Xcode
  2. Select the SwiftMediaBar scheme
  3. Build with ⌘+B or run with ⌘+R
  4. Run tests with ⌘+U

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Dependencies

  • media-control: Command-line tool for media information retrieval

License

This project is licensed under the MIT License.

Acknowledgments

  • ungive/media-control - Essential command-line tool that makes this app possible
  • menubar-ticker - General idea of a menu bar media ticker
  • Apple's MediaRemote framework - Underlying technology for media information access
  • The Swift and SwiftUI communities for excellent documentation and examples

Note: This app is not affiliated with Apple Inc. or any media application providers. It simply displays information that's already available through macOS's built-in media frameworks.

About

SwiftMediaBar is a sleek macOS menu bar application that displays your currently playing media information directly in the menu bar. It works with Apple Music, Spotify, and other media apps, showing song titles, artists, and album artwork in a clean, unobtrusive interface. Built with Swift, it uses the media-control CLI tool to fetch media data.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages