[UWP] Can MediaPlayer detect when it was played or paused by wired earphone button click

Md. Niaz Mahmud 171 Reputation points
2023-12-13T11:23:25.83+00:00

I am using MediaPlayer in UWP application. When I play UWP mediaplayer, and press my earphone play/pause button on-off , the media is played or paused. But my icon for play pause is not updated. Yes, there is an event handler MediaPlayer.CurrentStateChanged which is triggered during earphone play-pause and from "PlaybackSession.PlaybackState" argument we can detect whether media was played or paused. But Can we know which action cause this play/pause from any argument? Meaning, I want to know whether media was played or paused by "Earphone Button Action" or not. As, play/pause was not invoked programmatically. I need this because when play or pause action is only invoked only from earphone action I need to perform some different task

Developer technologies | Universal Windows Platform (UWP)
Developer technologies | C#
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 21,646 Reputation points
    2023-12-15T08:18:59.7+00:00

    Hi @Md. Niaz Mahmud ,

    Welcome to Microsoft Q&A!

    I want to know whether media was played or paused by "Earphone Button Action" or not.

    Currently there is no API in UWP that can achieve your needs.

    I also tried looking for related APIs in Win32 but couldn't find any. The feasible technical route is that you need to write your own driver to detect your earphone's events.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.