py_now_playing.core =================== .. py:module:: py_now_playing.core .. autoapi-nested-parse:: Py Now Playing - Playback Controls Module This module provides the PyNowPlaying class, which allows interaction with media playback controls on Windows. It includes methods to control playback, retrieve media information, and register callbacks for media events. Attributes ---------- .. autoapisummary:: py_now_playing.core.logger Classes ------- .. autoapisummary:: py_now_playing.core.PyNowPlaying Module Contents --------------- .. py:data:: logger .. py:class:: PyNowPlaying(*args, **kwargs) Playback Controls Class This class provides methods to control media playback and retrieve media information. It interacts with the Windows Media Control API to manage playback sessions. Attributes: aumid (str): The AppUserModelId of the application. _manager (MediaManager): The MediaManager instance for managing media sessions. .. py:method:: create(aumid: str) :classmethod: :async: Async factory method to initialize PyNowPlaying with a MediaManager. Args: aumid (str): The AppUserModelId of the application. Returns: PyNowPlaying: An initialized instance with MediaManager ready. .. py:method:: _init(aumid: str, media_manager: winrt.windows.media.control.GlobalSystemMediaTransportControlsSessionManager) :classmethod: Initializes the PyNowPlaying class. Args: aumid (str): The AppUserModelId of the application. media_manager (MediaManager): The MediaManager instance. Raises: ValueError: If aumid is None. .. py:method:: pause() -> bool :async: Pause the media Returns: bool: True if successful, False .. py:method:: play() -> bool :async: Play the media Returns: bool: True if successful, False .. py:method:: toggle_play_pause() -> bool :async: Toggle play/pause the media Returns: bool: True if successful, False .. py:method:: stop() -> bool :async: Stop the media Returns: bool: True if successful, False .. py:method:: record() -> bool :async: Tell the application to record Returns: bool: True if successful, False .. py:method:: rewind() -> bool :async: Rewind the media Returns: bool: True if successful, False .. py:method:: fast_forward() -> bool :async: Fast forward the media Returns: bool: True if successful, False .. py:method:: next_track() -> bool :async: Skip to the next track Returns: bool: True if successful, False .. py:method:: previous_track() -> bool :async: Skip to the previous track Returns: bool: True if successful, False .. py:method:: change_playback_rate(rate: float) -> bool :async: Changes the playback rate for supported apps/media. Args: rate (float): The new playback rate. Returns: bool: True if successful, False .. py:method:: change_shuffle_active(state: bool) -> bool :async: Changes the shuffle active state. Args: state (bool): The new shuffle active state. Returns: bool: True if successful, False .. py:method:: change_auto_repeat_mode(mode: int) -> bool :async: Changes the auto repeat mode. Args: mode (int): The new auto repeat mode. 0 = None, 1 = Track, 2 = List Returns: bool: True if successful, False .. py:method:: seek(position: int) -> bool :async: Changes the playback position (Time Elapsed) Args: position (int): The new playback position in seconds. Returns: bool: True if successful, False .. py:method:: channel_up() -> bool :async: Sends a channel up command to the media session. Returns: bool: True if successful, False .. py:method:: channel_down() -> bool :async: Sends a channel down command to the media session. Returns: bool: True if successful, False .. py:method:: get_timeline_properties() -> py_now_playing.dataclasses.media_timeline.MediaTimeline | None :async: Gets the timeline properties of the media. Note: Windows updates the Media Timeline information at it's own pace, so if you want a live position marker, use get_interpolated_timeline_properties() Returns: MediaTimeline: The timeline properties of the media. .. py:method:: get_interpolated_timeline_properties() -> py_now_playing.dataclasses.media_timeline.MediaTimeline | None :async: Gets the interpolated timeline properties of the media. Note: MediaTimeline.last_updated_time is the last update by WinRT, not since the update of this function. Returns: MediaTimeline: The interpolated timeline properties of the media. .. py:method:: get_thumbnail() -> PIL.Image.Image | None :async: Gets the thumbnail of the media. Returns: Image: The thumbnail of the media as a PIL Image. .. py:method:: get_media_info() -> py_now_playing.dataclasses.media_info.MediaInfo | None :async: Gets the media info of the media. Returns: MediaInfo: The media info of the media. .. py:method:: get_playback_info() -> py_now_playing.dataclasses.playback_info.PlaybackInfo | None :async: Gets the playback info of the media. Returns: PlaybackInfo: The playback info of the media. .. py:method:: thumbnail_to_image(thumbnail) -> PIL.Image.Image | None :async: Converts a thumbnail to a PIL Image. Args: thumbnail: The thumbnail to convert. Returns: Image: The PIL Image. .. py:method:: get_active_app_user_model_ids() -> list[dict[str, str]] :staticmethod: :async: Gets AppUserModelIds of apps which are actively playing media. Returns: list: The active AppUserModelIds in the format [{Name, AppID}, ...] .. py:method:: get_all_aumids_by_name(name: str) -> list[str] | None :staticmethod: :async: Gets the AUMID by the name of the app. Note that this gets the first match of the app name. If there are multiple apps with the same name, it will return the first one installed on your system, not the one currently running. Args: name (str): The name of the app. Returns: list[str]: A list of AppUserModelIds that match the name. None: If no matches are found. .. py:method:: _internal_playback_info_changed_callback(sender, args) Internal callback for playback info changes. .. py:method:: _internal_timeline_properties_changed_callback(sender, args) Internal callback for timeline properties changes. .. py:method:: _internal_media_properties_changed_callback(sender, args) Internal callback for media properties changes. .. py:method:: register_playback_info_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.playback_info.PlaybackInfo], None]) -> None Registers a callback for playback info changes. Args: callback: The callback function. .. py:method:: register_timeline_properties_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.media_timeline.MediaTimeline], None]) -> None Registers a callback for timeline properties changes. Args: callback: The callback function. .. py:method:: register_media_properties_changed_callback(callback: Callable[[winrt.windows.media.control.GlobalSystemMediaTransportControlsSession, py_now_playing.dataclasses.media_info.MediaInfo], None]) -> None Registers a callback for media properties changes. Args: callback: The callback function. .. py:method:: deregister_playback_info_changed_callback() -> None Deregisters the playback info changed callback. .. py:method:: deregister_timeline_properties_changed_callback() -> None Deregisters the timeline properties changed callback. .. py:method:: deregister_media_properties_changed_callback() -> None Deregisters the media properties changed callback.