我想创建一个程序,可以使用 C# 手动更改在我的 PC 上播放的媒体的优先级。
这是因为我键盘上的播放/暂停按钮没有固定在我想要的程序上。
在我看来,正在播放的媒体将存储在堆栈中,我想将我想要访问的程序推到顶部,以便键盘播放/暂停它。 堆栈例如:
顶部的项目 (Spotify) 将是通过播放/暂停键访问的项目。
我不确定 Windows 是如何处理这个的,所以任何信息将不胜感激。
我还没有尝试过任何东西,因为我不知道从哪里开始,或者这是否可能。
您可以通过获取进程并像这样设置它的优先级来更改 Windows 中的媒体优先级:
using System;
using System.Diagnostics;
namespace ProcessRealtime
{
class Program
{
static void Main(string[] args)
{
// Define the names of the media processes
string[] mediaProcesses = new string[] { "Spotify", "Chrome", "Opera" };
// Loop through the media processes
foreach (string mediaProcess in mediaProcesses)
{
// Get the processes by name
Process[] processes = Process.GetProcessesByName(mediaProcess);
// Loop through the processes
foreach (Process proc in processes)
{
// Change the priority to RealTime
proc.PriorityClass = ProcessPriorityClass.RealTime;
// Print a message
Console.WriteLine("Changed priority for {0} to RealTime", proc.ProcessName);
}
}
// Wait for a key press
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
然后您可以为定义的组合键添加诸如事件监听器之类的东西,以便您可以切换当前优先级。