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

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

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

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

EndRewind(CancellationToken)

Ends a previously started rewind.

public Task EndRewind(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

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

HomeHold(CancellationToken)

Hold key home.

public Task HomeHold(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

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

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

Next(CancellationToken)

Press key next.

public Task Next(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

Pause(CancellationToken)

Press key play.

public Task Pause(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

Play(CancellationToken)

Press key play.

public Task Play(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

PlayPause(CancellationToken)

Toggle between play and pause.

public Task PlayPause(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

Previous(CancellationToken)

Press key previous.

public Task Previous(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

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

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

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

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

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

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

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

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

Stop(CancellationToken)

Press key stop.

public Task Stop(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

Suspend(CancellationToken)

Suspend the device.

public Task Suspend(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

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

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

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

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

VolumeDown(CancellationToken)

Press key volume down.

public Task VolumeDown(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

VolumeUp(CancellationToken)

Press key volume up.

public Task VolumeUp(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task

Wakeup(CancellationToken)

Wake up the device.

public Task Wakeup(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the operation.

Returns

Task