Table of Contents

Class MrpRemoteControl

Namespace
AppleTvControlLibrary.Mrp.RemoteControl
Assembly
AppleTvControlLibrary.Mrp.dll

Implementation of the MRP remote-control command surface: directional/menu/select HID keys, playback transport commands, seek, repeat/shuffle, and absolute volume.

public sealed class MrpRemoteControl
Inheritance
MrpRemoteControl
Inherited Members

Remarks

Initializes a new instance of the MrpRemoteControl class.

Constructors

MrpRemoteControl(MrpProtocol, MrpPlayerStateManager, HttpClient?)

Implementation of the MRP remote-control command surface: directional/menu/select HID keys, playback transport commands, seek, repeat/shuffle, and absolute volume.

public MrpRemoteControl(MrpProtocol protocol, MrpPlayerStateManager playerStateManager, HttpClient? httpClient = null)

Parameters

protocol MrpProtocol

The MRP protocol instance used to send/receive messages.

playerStateManager MrpPlayerStateManager

The player state manager used to look up command capabilities.

httpClient HttpClient

The HTTP client used to fetch remote artwork (e.g. iTunes-hosted artwork referenced by artworkIdentifier/artworkURL). If not supplied, a default instance is created.

Remarks

Initializes a new instance of the MrpRemoteControl class.

Methods

BeginFastForward(CancellationToken)

Begin fast-forwarding through the current media.

public Task BeginFastForward(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the fast-forward start command has been sent and any required reply received.

BeginRewind(CancellationToken)

Begins rewinding through the current media.

public Task BeginRewind(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the rewind start command has been sent and any required reply received.

Down(InputAction, CancellationToken)

Press key down.

public Task Down(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the down-key sequence has been sent and any required reply received.

EndFastForward(CancellationToken)

Ends a previously started fast-forward.

public Task EndFastForward(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the fast-forward stop command has been sent and any required reply received.

EndRewind(CancellationToken)

Ends a previously started rewind.

public Task EndRewind(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the rewind stop command has been sent and any required reply received.

GetArtworkAsync(int, int, CancellationToken)

Fetches artwork for the currently playing item, mirroring pyatv's MrpMetadata.artwork(): checks a small identifier-keyed cache first, then attempts a remote (HTTP) fetch using artworkIdentifier/artworkURL metadata, and falls back to an in-band MRP fetch (GetLocalArtworkAsync(int, int, CancellationToken)) if the remote fetch does not produce a result. All fetch failures (HTTP errors, malformed URL templates, cancelled/failed MRP round-trips) are valid outcomes — not every item has artwork, and a device may reject the request — so they are handled by returning null rather than propagating.

public Task<(byte[] Data, string? MimeType)?> GetArtworkAsync(int width = -1, int height = 400, CancellationToken cancellationToken = default)

Parameters

width int

The requested artwork width, or -1 for no preference.

height int

The requested artwork height, or -1 for no preference.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task<(byte[] Data, string MimeType)?>

The artwork bytes and MIME type, or null if no artwork is available.

GetLocalArtworkAsync(int, int, CancellationToken)

Explicitly fetches artwork bytes for the currently playing item directly over MRP, bypassing the remote-URL fetch and cache used by GetArtworkAsync(int, int, CancellationToken).

public Task<(byte[] Data, string? MimeType)?> GetLocalArtworkAsync(int width = -1, int height = 400, CancellationToken cancellationToken = default)

Parameters

width int

The requested artwork width, or -1 for no preference.

height int

The requested artwork height, or -1 for no preference.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task<(byte[] Data, string MimeType)?>

The artwork bytes and MIME type, or null if no artwork is available.

Home(InputAction, CancellationToken)

Press key home.

public Task Home(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the home-key sequence has been sent and any required reply received.

HomeHold(CancellationToken)

Hold key home.

public Task HomeHold(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the home-key hold has been sent and any required reply received.

Left(InputAction, CancellationToken)

Press key left.

public Task Left(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the left-key sequence has been sent and any required reply received.

Menu(InputAction, CancellationToken)

Press key menu.

public Task Menu(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the menu-key sequence has been sent and any required reply received.

Next(CancellationToken)

Press key next.

public Task Next(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the next-track command has been sent and any required reply received.

Pause(CancellationToken)

Press key play.

public Task Pause(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the pause command has been sent and any required reply received.

Play(CancellationToken)

Press key play.

public Task Play(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the play command has been sent and any required reply received.

PlayPause(CancellationToken)

Toggle between play and pause.

public Task PlayPause(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the selected playback toggle or fallback command has been sent and any required reply received.

Previous(CancellationToken)

Press key previous.

public Task Previous(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the previous-track command has been sent and any required reply received.

Right(InputAction, CancellationToken)

Press key right.

public Task Right(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the right-key sequence has been sent and any required reply received.

Select(InputAction, CancellationToken)

Press key select.

public Task Select(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the select-key sequence has been sent and any required reply received.

SetPosition(int, CancellationToken)

Seek in the current playing media.

public Task SetPosition(int position, CancellationToken cancellationToken = default)

Parameters

position int

The absolute position, in seconds.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the seek command has been sent and any required reply received.

SetRepeat(RepeatState, CancellationToken)

Change repeat state.

public Task SetRepeat(RepeatState repeatState, CancellationToken cancellationToken = default)

Parameters

repeatState RepeatState

The repeat mode to set.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the repeat command has been sent and any required reply received.

SetShuffle(ShuffleState, CancellationToken)

Change shuffle mode to on or off.

public Task SetShuffle(ShuffleState shuffleState, CancellationToken cancellationToken = default)

Parameters

shuffleState ShuffleState

The shuffle mode to set.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the shuffle command has been sent and any required reply received.

SetVolume(string, float, CancellationToken)

Change volume on a device.

public Task SetVolume(string deviceUid, float volume, CancellationToken cancellationToken = default)

Parameters

deviceUid string

The output device identifier.

volume float

The volume level, in the range 0.0-1.0.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the output-volume message has been sent and any required reply received.

SkipBackward(double, CancellationToken)

Skip backwards a time interval. Skip interval is typically 15-30s, but is decided by the app.

public Task SkipBackward(double timeInterval = 0, CancellationToken cancellationToken = default)

Parameters

timeInterval double

The number of seconds to skip, or 0 to use the app's preferred interval.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the skip-backward command has been sent and any required reply received.

SkipForward(double, CancellationToken)

Skip forward a time interval. Skip interval is typically 15-30s, but is decided by the app.

public Task SkipForward(double timeInterval = 0, CancellationToken cancellationToken = default)

Parameters

timeInterval double

The number of seconds to skip, or 0 to use the app's preferred interval.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the skip-forward command has been sent and any required reply received.

Stop(CancellationToken)

Press key stop.

public Task Stop(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the stop command has been sent and any required reply received.

Suspend(CancellationToken)

Suspend the device.

public Task Suspend(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the suspend key has been sent and any required reply received.

TopMenu(CancellationToken)

Go to main menu (long press menu).

public Task TopMenu(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the main-menu key sequence has been sent and any required reply received.

TurnOff(CancellationToken)

Turns the device "off": on tvOS this dismisses to the screensaver rather than a true power off (MRP has no dedicated power-off message; see the DeviceInfoMessage.logicalDeviceCount == 0 check pyatv uses to detect the resulting Off power state).

public Task TurnOff(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the home-hold and select sequence has been sent and any required reply received.

TurnOn(CancellationToken)

Turn the device on. Unlike Wakeup(CancellationToken), which sends a "wakeup" SEND_HID_EVENT_MESSAGE (HID usage-page/usage pair (1, 0x83), not a HID-protocol transport), this sends the dedicated WAKE_DEVICE_MESSAGE protobuf message directly.

public Task TurnOn(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the wake-device message has been sent and any required reply received.

Up(InputAction, CancellationToken)

Press key up.

public Task Up(InputAction action = InputAction.SingleTap, CancellationToken cancellationToken = default)

Parameters

action InputAction

The type of press to perform.

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the up-key sequence has been sent and any required reply received.

VolumeDown(CancellationToken)

Press key volume down.

public Task VolumeDown(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the volume-down key has been sent and any required reply received.

VolumeUp(CancellationToken)

Press key volume up.

public Task VolumeUp(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the volume-up key has been sent and any required reply received.

Wakeup(CancellationToken)

Wake up the device.

public Task Wakeup(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

A task that completes when the wakeup key has been sent and any required reply received.