The keyboard shortcuts such as Play
, Pause
and so on you mean here are actually the System Media Transport Controls(SMTC).
can anyone help me out with proper way of implementing the keyboard music controls?
Actually, starting with Windows 10, version 1607, UWP apps that use the MediaPlayer
class to play media are automatically integrated with the SMTC by default. Simply instantiate a new instance of MediaPlayer
and assign a MediaSource
, MediaPlaybackItem
, or MediaPlaybackList
to the player's Source property and the user will see your app name in the SMTC and can play, pause, and move through your playback lists by using the SMTC controls.
This is the recommended way of interacting with the SMTC for most scenarios.Details please reference Integrate with the System Media Transport Controls. There are a few scenarios where you may need to implement manual control of the SMTC. For this please reference Manual control of the System Media Transport Controls.
but i need it to work even in background.
According to the remark section of SystemMediaTransportControls
class:
The system transport control allows a user to control a music application that is in the background as well as get and set the current information on which track is playing.
So that SMTC should also work for music in background.
For a sample please reference the official sample.