pyatv icon indicating copy to clipboard operation
pyatv copied to clipboard

Mute function

Open hieusinh25 opened this issue 1 year ago • 1 comments

What do you need help with?

I have use the setvolume to zero to work with mute function. but I don't get the latest volume to back to old state. when change volume on appletv, have one subscribe event to listening current volume? tks you

@postlund

hieusinh25 avatar Nov 13 '24 04:11 hieusinh25

This can be achieved by sending a HID key: consumer page 12 / usage 0xE2

I'm using the following hack, where self._atv is pyatv.interface.AppleTV:

from pyatv.protocols.mrp import MrpRemoteControl, messages
...
    async def mute_toggle(self)
        """Press mute key."""
        await self._send_hid_key(12, 0xE2)
...
    async def _send_hid_key(self, use_page: int, usage: int) -> None:
        """Send a short HID key press.

        :param use_page: HID usage page (1 Generic Desktop, 7 Keyboard, 12 Consumer)
        :param usage: HID key usage
        """
        if self._atv and isinstance(self._atv.remote_control.main_instance, MrpRemoteControl):
            await self._atv.remote_control.main_instance.protocol.send(messages.send_hid_event(use_page, usage, True))
            await self._atv.remote_control.main_instance.protocol.send(messages.send_hid_event(use_page, usage, False))
        else:
            _LOG.warning("[%s] send HID key not supported (%d, %d)", self.log_id, use_page, usage)
...

Tested on Apple TV 4 HD & 4k

zehnm avatar Apr 05 '25 14:04 zehnm