Properly integrate GlobalSystemMediaTransportControlsSession

Marcel Lorenz 81 Reputation points

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?

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,630 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,586 Reputation points

    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.