Skip to main content

Windows System Media Controller with Async Support

Project description

winmedia_controller

A simple Python library for controlling and monitoring media playback on Windows using hotkeys and the Windows Media Control API.

WARN: Please install package winrt manualy, my script is 100% work!

Overview

winmedia_controller allows you to control media playback (play/pause, next track, previous track) and retrieve information about the currently playing media (e.g., title, artist, album, playback status, progress) on Windows. It uses hotkeys for easy control and supports asynchronous operations for efficient media monitoring.

Features

  • Toggle playback (play/pause) with a hotkey.
  • Skip to the next or previous track using hotkeys.
  • Monitor real-time media information (title, artist, album, playback status, progress, etc.).
  • Asynchronous design for non-blocking operations.
  • Easy integration with any Windows media player supporting the Media Control API.

Requirements

  • Operating System: Windows (the library uses Windows-specific APIs).
  • Python: 3.7 or higher.
  • Dependencies:
    • winrt-python (for Windows Runtime support)
    • keyboard (for hotkey functionality)

Installation

  1. Clone or download this repository to your local machine.

  2. Navigate to the root directory of the project.

  3. Install the required dependencies using pip:

    pip install -r requirements.txt
    

    If requirements.txt is not present, install the dependencies manually:

    pip install winrt-python keyboard
    
  4. (Optional) Install the library locally for development:

    pip install -e .
    

Usage

Here’s a simple example of how to use winmedia_controller to control media and monitor playback:

import asyncio
from winmedia_controller.media_controller import MediaController

async def print_media_info():
    controller = MediaController()
    while True:
        info = await controller.get_media_info()
        if info:
            print(f"Media Info: {info}")
        await asyncio.sleep(1)  # Check every second

async def main():
    controller = MediaController()
    await print_media_info()

if __name__ == "__main__":
    asyncio.run(main())

Hotkeys

By default, the library uses the following hotkey combinations:

  • play/pause media: Toggles playback (play or pause).
  • next track: Skips to the next track.
  • previous track: Skips to the previous track.

You can modify these hotkeys by editing the _setup_hotkeys method in media_controller.py.

Monitoring Media

The monitor method allows you to continuously monitor media playback and call a callback function with the current media information:

async def on_media_update(info):
    print(f"Current song: {info['title']} by {info['artist']} - {info['status']}")

controller = MediaController()
await controller.monitor(callback=on_media_update, interval=1)  # Check every second

Building the Library

To build and distribute winmedia_controller as a Python package:

  1. Ensure setup.py and pyproject.toml are properly configured with project metadata and dependencies.

  2. Run the following command to build the package:

    python setup.py sdist bdist_wheel
    
  3. Install the built package locally:

    pip install dist/winmedia_controller-0.1.0-py3-none-any.whl
    

Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you’d like to change.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on this repository or contact [your contact information here].

Project details


Release history Release notifications | RSS feed

This version

1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

winmedia_controller-1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

winmedia_controller-1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file winmedia_controller-1.1.tar.gz.

File metadata

  • Download URL: winmedia_controller-1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for winmedia_controller-1.1.tar.gz
Algorithm Hash digest
SHA256 1258302286965beb832072e50df528c7f057fd64ff9b537d2d89fd7327b468c9
MD5 dd390bc1d1f5b65a6fcac085c781bcac
BLAKE2b-256 32ebfafde1ce2c981a7fe8525d309d94340c9d56eb032c589e49cf3a192dccf7

See more details on using hashes here.

File details

Details for the file winmedia_controller-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for winmedia_controller-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e655f86894d936ffda011179bcb0c82f85f11ef88afe1ede9eaf4d1e473bea9
MD5 8399be01f1972eb2e757e82431831da6
BLAKE2b-256 bfa5e216e9265cc60c7f65629df0a61638aca0339864d5c70cefeebb2b18ba64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page