Search code examples
c#wpfmedia-player

How to use SystemMediaTransportControls in WPF Application?


Is there any way to create an SystemMediaTransportControls-object in WPF?

I followed this guide to access the Windows 10 APIs from my WPF-Application. I can call the class but I can't create an object. In a UWP-App you create it like this:

SystemMediaTransportControls smtp = SystemMediaTransportControls.GetForCurrentView();

But by calling this method in WPF, I'm getting an "Invalid window handle" exception at this line.

public partial class MainWindow : Window
{
    SystemMediaTransportControls smtp;

    public MainWindow()
    {
        InitializeComponent();
        //SMTP Einrichten
        smtp = SystemMediaTransportControls.GetForCurrentView();
    }

[...]
}

Apparently, GetForCurrentView() is not working in WPF but what to use instead?


Solution

  • SystemMediaTransportControls isn't supported in desktop apps. It can only be used in UWP apps.

    See UWP APIs callable from a classic desktop app, which says:

    If the DualApiPartition attribute is not listed

    In this case, the API is not allowed to be called from a classic desktop app. Windows.UI.Xaml.Controls.Button is an example.

    SystemMediaTransportControls does not have the DualApiPartition attribute.

    The How do I know which APIs are available? section of guide you linked references the list of UWP APIs available to a packaged desktop app (Desktop Bridge) , and this also does not list SystemMediatTransportControls as available.