Properly integrate GlobalSystemMediaTransportControlsSession

Marcel Lorenz 81 Reputation points
2021-03-16T16:32:18.66+00:00

I use the MediaPlayerElement from Microsoft.Toolkit.Forms.UI.Controls. Now I want to properly integrate the GlobalSystemMediaTransportControlsSession. I can be read out using the GlobalSystemMediaTransportControlsSessionManager but I cannot control the session using for example TryPauseAsync, TryPlayAsync, TrySkipNextAsync, TrySkipPreviousAsync, ... Also I want to set the metadata like Title, Artist, State, and TimelineProperties.

How can I do this?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 Reputation points
    2021-03-17T02:41:59.4+00:00

    Methods such as TryPauseAsync and TryPlayAsync belong to GlobalSystemMediaTransportControlsSession instead of GlobalSystemMediaTransportControlsSessionManager. We should be free to use these methods according to the GlobalSystemMediaTransportControlsSession object.

                GlobalSystemMediaTransportControlsSession currentSession = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult().GetCurrentSession();  
                await currentSession.TryPlayAsync();  
               //......  
    

    How are you using them?

    Also I want to set the metadata like Title, Artist, State, and TimelineProperties.

    I did not find a way to do this, it seems that the current API does not support this.

    Maybe you can refer to the solution in this link and use other packages to do it.


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.