MediaControl MediaControl MediaControl MediaControl MediaControl Class

Definition

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Describes the object that applications register with, to receive media focus and transport control notifications.

public : static class MediaControl
static struct winrt::Windows::Media::MediaControl
public static class MediaControl
Public Static Class MediaControl
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows Desktop Extension SDK (introduced v10.0.10240.0) Xbox One Extensions for the UWP (introduced v10.0.10586.0)
API contract
Windows.Media.MediaControlContract (introduced v1)

Remarks

The MediaControl class provides access to button press events. These events can be monitored, and can modify the response and behavior of an audio-aware app. Here is a JavaScript code snippet that shows how to add event listeners to a MediaControl object. It then shows how to write code to handle those events.

// Assign the Windows.Media.MediaControl button object to 
// the user-defined mediaControls variable
mediaControls = Windows.Media.MediaControl;

// Add event listeners for the buttons
mediaControls.addEventListener(“PlayPressed”, play, false);
mediaControls.addEventListener(“PausePressed”, pause, false);
mediaControls.addEventListener(“PlayPauseTogglePressed”, playpausetoggle, false);
mediaControls.addEventListener(“NextTrackPressed”, nexttrack, false);
mediaControls.addEventListener(“PreviousTrackPressed”, previoustrack, false);
mediaControls.addEventListener(“SoundLevelChanged”, soundlevelchanged, false);

// Add code for event handlers for the events
   function play() {
      document.getElementById(“audiotag”).play();
   }

   function pause() {
      document.getElementById(“audiotag”).pause();
   }

   function playpausetoggle() {
      //<code goes here to handle the PlayPauseToggle event> 
   }

   ...
   // Additional code to handle the other events

To see the complete listing for this example, see How to configure keys for media controls.

Properties

AlbumArt AlbumArt AlbumArt AlbumArt AlbumArt

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Gets or sets the path to the artwork for the album cover.

public : static Uri AlbumArt { get; set; }
static Uri AlbumArt();

static void AlbumArt(Uri albumart);
public static Uri AlbumArt { get; set; }
Public Static ReadWrite Property AlbumArt As Uri
var uri = Windows.Media.MediaControl.albumArt;
mediaControl.albumArt = uri;
Value
Uri Uri Uri

Path to the artwork for the album cover.

Remarks

If you provide an invalid path for the album art property, it will cause an exception to be thrown. The only valid URI formats are ms-appx:// and ms-appdata://.

ArtistName ArtistName ArtistName ArtistName ArtistName

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Gets or sets the name of the artist.

public : static Platform::String ArtistName { get; set; }
static winrt::hstring ArtistName();

static void ArtistName(winrt::hstring artistname);
public static string ArtistName { get; set; }
Public Static ReadWrite Property ArtistName As string
var string = Windows.Media.MediaControl.artistName;
mediaControl.artistName = string;
Value
string string string

The name of the artist.

IsPlaying IsPlaying IsPlaying IsPlaying IsPlaying

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Gets or sets the state of the Play button.

public : static Platform::Boolean IsPlaying { get; set; }
static bool IsPlaying();

static void IsPlaying(bool isplaying);
public static bool IsPlaying { get; set; }
Public Static ReadWrite Property IsPlaying As bool
var bool = Windows.Media.MediaControl.isPlaying;
mediaControl.isPlaying = bool;
Value
bool bool bool

The state of the Play button.

Remarks

IsPlaying is a Boolean value that indicates the state of the Play button. You can retrieve or set this value. You can also use the current value to make programmatic decisions about the behavior of the app.

See Also

SoundLevel SoundLevel SoundLevel SoundLevel SoundLevel

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Gets the current sound level.

public : static SoundLevel SoundLevel { get; }
static SoundLevel SoundLevel();
public static SoundLevel SoundLevel { get; }
Public Static ReadOnly Property SoundLevel As SoundLevel
var soundLevel = Windows.Media.MediaControl.soundLevel;
Value
SoundLevel SoundLevel SoundLevel

The current sound level.

Remarks

Note that the sound level of an application is tied to the state of its render streams only, and not to the states of its capture or loopback streams.

See Also

TrackName TrackName TrackName TrackName TrackName

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Gets or sets the track name.

public : static Platform::String TrackName { get; set; }
static winrt::hstring TrackName();

static void TrackName(winrt::hstring trackname);
public static string TrackName { get; set; }
Public Static ReadWrite Property TrackName As string
var string = Windows.Media.MediaControl.trackName;
mediaControl.trackName = string;
Value
string string string

The name of the track.

Events

ChannelDownPressed ChannelDownPressed ChannelDownPressed ChannelDownPressed ChannelDownPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a ChannelDown command is issued to the application.

public : event EventHandler ChannelDownPressed<Platform::Object>
// Register
event_token ChannelDownPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void ChannelDownPressed(event_token const& cookie) const;

// Revoke with event_revoker
ChannelDownPressed_revoker ChannelDownPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler ChannelDownPressed<object>
Public Event EventHandler ChannelDownPressed( Of ( Of object ))
function onChannelDownPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("channelDownPressed", onChannelDownPressed);
mediaControl.removeEventListener("channelDownPressed", onChannelDownPressed);

ChannelUpPressed ChannelUpPressed ChannelUpPressed ChannelUpPressed ChannelUpPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a ChannelUp command is issued to the application.

public : event EventHandler ChannelUpPressed<Platform::Object>
// Register
event_token ChannelUpPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void ChannelUpPressed(event_token const& cookie) const;

// Revoke with event_revoker
ChannelUpPressed_revoker ChannelUpPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler ChannelUpPressed<object>
Public Event EventHandler ChannelUpPressed( Of ( Of object ))
function onChannelUpPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("channelUpPressed", onChannelUpPressed);
mediaControl.removeEventListener("channelUpPressed", onChannelUpPressed);

FastForwardPressed FastForwardPressed FastForwardPressed FastForwardPressed FastForwardPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a FastForward command is issued to the application.

public : event EventHandler FastForwardPressed<Platform::Object>
// Register
event_token FastForwardPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void FastForwardPressed(event_token const& cookie) const;

// Revoke with event_revoker
FastForwardPressed_revoker FastForwardPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler FastForwardPressed<object>
Public Event EventHandler FastForwardPressed( Of ( Of object ))
function onFastForwardPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("fastForwardPressed", onFastForwardPressed);
mediaControl.removeEventListener("fastForwardPressed", onFastForwardPressed);

NextTrackPressed NextTrackPressed NextTrackPressed NextTrackPressed NextTrackPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a NextTrack command is issued to the application.

public : event EventHandler NextTrackPressed<Platform::Object>
// Register
event_token NextTrackPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void NextTrackPressed(event_token const& cookie) const;

// Revoke with event_revoker
NextTrackPressed_revoker NextTrackPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler NextTrackPressed<object>
Public Event EventHandler NextTrackPressed( Of ( Of object ))
function onNextTrackPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("nextTrackPressed", onNextTrackPressed);
mediaControl.removeEventListener("nextTrackPressed", onNextTrackPressed);
See Also

PausePressed PausePressed PausePressed PausePressed PausePressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a Pause command is issued to the application.

public : event EventHandler PausePressed<Platform::Object>
// Register
event_token PausePressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void PausePressed(event_token const& cookie) const;

// Revoke with event_revoker
PausePressed_revoker PausePressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler PausePressed<object>
Public Event EventHandler PausePressed( Of ( Of object ))
function onPausePressed(eventArgs){/* Your code */}


mediaControl.addEventListener("pausePressed", onPausePressed);
mediaControl.removeEventListener("pausePressed", onPausePressed);
See Also

PlayPauseTogglePressed PlayPauseTogglePressed PlayPauseTogglePressed PlayPauseTogglePressed PlayPauseTogglePressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a PlayPauseToggle command is issued to the application.

public : event EventHandler PlayPauseTogglePressed<Platform::Object>
// Register
event_token PlayPauseTogglePressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void PlayPauseTogglePressed(event_token const& cookie) const;

// Revoke with event_revoker
PlayPauseTogglePressed_revoker PlayPauseTogglePressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler PlayPauseTogglePressed<object>
Public Event EventHandler PlayPauseTogglePressed( Of ( Of object ))
function onPlayPauseTogglePressed(eventArgs){/* Your code */}


mediaControl.addEventListener("playPauseTogglePressed", onPlayPauseTogglePressed);
mediaControl.removeEventListener("playPauseTogglePressed", onPlayPauseTogglePressed);
See Also

PlayPressed PlayPressed PlayPressed PlayPressed PlayPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a Play command is issued to the application.

public : event EventHandler PlayPressed<Platform::Object>
// Register
event_token PlayPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void PlayPressed(event_token const& cookie) const;

// Revoke with event_revoker
PlayPressed_revoker PlayPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler PlayPressed<object>
Public Event EventHandler PlayPressed( Of ( Of object ))
function onPlayPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("playPressed", onPlayPressed);
mediaControl.removeEventListener("playPressed", onPlayPressed);
See Also

PreviousTrackPressed PreviousTrackPressed PreviousTrackPressed PreviousTrackPressed PreviousTrackPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a PreviousTrack command is issued to the application.

public : event EventHandler PreviousTrackPressed<Platform::Object>
// Register
event_token PreviousTrackPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void PreviousTrackPressed(event_token const& cookie) const;

// Revoke with event_revoker
PreviousTrackPressed_revoker PreviousTrackPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler PreviousTrackPressed<object>
Public Event EventHandler PreviousTrackPressed( Of ( Of object ))
function onPreviousTrackPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("previousTrackPressed", onPreviousTrackPressed);
mediaControl.removeEventListener("previousTrackPressed", onPreviousTrackPressed);
See Also

RecordPressed RecordPressed RecordPressed RecordPressed RecordPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a Record command is issued to the application.

public : event EventHandler RecordPressed<Platform::Object>
// Register
event_token RecordPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void RecordPressed(event_token const& cookie) const;

// Revoke with event_revoker
RecordPressed_revoker RecordPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler RecordPressed<object>
Public Event EventHandler RecordPressed( Of ( Of object ))
function onRecordPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("recordPressed", onRecordPressed);
mediaControl.removeEventListener("recordPressed", onRecordPressed);

RewindPressed RewindPressed RewindPressed RewindPressed RewindPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a Rewind command is issued to the application.

public : event EventHandler RewindPressed<Platform::Object>
// Register
event_token RewindPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void RewindPressed(event_token const& cookie) const;

// Revoke with event_revoker
RewindPressed_revoker RewindPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler RewindPressed<object>
Public Event EventHandler RewindPressed( Of ( Of object ))
function onRewindPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("rewindPressed", onRewindPressed);
mediaControl.removeEventListener("rewindPressed", onRewindPressed);

SoundLevelChanged SoundLevelChanged SoundLevelChanged SoundLevelChanged SoundLevelChanged

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when the sound level changes.

public : event EventHandler SoundLevelChanged<Platform::Object>
// Register
event_token SoundLevelChanged(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void SoundLevelChanged(event_token const& cookie) const;

// Revoke with event_revoker
SoundLevelChanged_revoker SoundLevelChanged(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler SoundLevelChanged<object>
Public Event EventHandler SoundLevelChanged( Of ( Of object ))
function onSoundLevelChanged(eventArgs){/* Your code */}


mediaControl.addEventListener("soundLevelChanged", onSoundLevelChanged);
mediaControl.removeEventListener("soundLevelChanged", onSoundLevelChanged);
See Also

StopPressed StopPressed StopPressed StopPressed StopPressed

Note

MediaControl may be altered or unavailable for releases after Windows 8.1. Instead, use SystemMediaTransportControls.

Event raised when a Stop command is issued to the application.

public : event EventHandler StopPressed<Platform::Object>
// Register
event_token StopPressed(EventHandler<Platform::Object> const& handler) const;

// Revoke with event_token
void StopPressed(event_token const& cookie) const;

// Revoke with event_revoker
StopPressed_revoker StopPressed(auto_revoker_t, EventHandler<Platform::Object> const& handler) const;
public event EventHandler StopPressed<object>
Public Event EventHandler StopPressed( Of ( Of object ))
function onStopPressed(eventArgs){/* Your code */}


mediaControl.addEventListener("stopPressed", onStopPressed);
mediaControl.removeEventListener("stopPressed", onStopPressed);

See Also