c# - unexpected time error for GlobalSystemMediaTransportControlsSessionManager

  • Thread starter Thread starter Hamidreza-B
  • Start date Start date
H

Hamidreza-B

Guest
I'm trying to get the current playing song with GlobalSystemMediaTransportControlsSessionManager base on Using SystemMediaTransportControls to get current playing song info from other app

but when i run this i get this error:

Unhandled Exception: System.InvalidOperationException: A method was called at an unexpected time.
A method was called at an unexpected time.
at Windows.Foundation.IAsyncOperation`1.GetResults() at ConsoleApp1.Program.Main(String[] args) in C:\Users\hamid\source\repos\ConsoleApp1\Program.cs:line 10

I have also removed GetAwaiter() because it could't find it.

this is my code:

using System;
using Windows.Media.Control;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var gsmtcsm = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetResults().GetCurrentSession();
var mediaProperties = gsmtcsm.TryGetMediaPropertiesAsync().GetResults();
Console.WriteLine("{0} - {1}", mediaProperties.Artist, mediaProperties.Title);
}
}
}
What is the problem?

Continue reading...
 
Back
Top