From 148fb60b9aa801631f849a3f25b8dc5847796d51 Mon Sep 17 00:00:00 2001 From: kjqwer <2990346238@qq.com> Date: Thu, 26 Feb 2026 07:26:04 +0800 Subject: [PATCH] =?UTF-8?q?aimp=E4=BD=BF=E7=94=A8=E8=87=AA=E4=B9=89?= =?UTF-8?q?=E5=AE=9A=E7=9A=84=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MediaControl.exe | Bin 35328 -> 38400 bytes MediaControl.ps1 | 92 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/MediaControl.exe b/MediaControl.exe index e9b0633dbe7ea3e07e19ed1ad7114b495e32fdd9..5ce921bbbb0608d492efae8797a87813af73f658 100644 GIT binary patch delta 1686 zcmb_dU1%It6uvWV{x;p!rf9W)-cAO0C)r8Xn6A1evLXI7*vh6W25Ab8$!$8gJF}g+ z+a{*cP0<=lnr3qfY6Vvzr5J>!OesQ)27K|&2NBGR65uLR;YYSUbGIh5X_<=E6)T;2hUjx5%t&rju}k zd%SL$S?pwV5q{-_Cy;$Hll@G2RE5$Rg!((!HEce>!lszL6lEtjSxG*zi~l)lP4D@w z>Q%8z&17F3CP{@J!<|^@j`t@GeaKKU_$4(>%>J&PgGuMpLWYSD@CW=ybJ_q^bq&8p zOe)*)hjN;xYD0JwPB*neM`(AoV226tW=Pzk9>rlXYv=>SG+{Y>2yTaJeYP9!wzj~Z zkp>u+ni_hv6Z+f4IjvjIWE5=>KI&|2I>-!#>c$AeCQ>6uq$2@8_T=#EN?K)Zk|Hz= zw>ul3{D;@11_O0O^v;W{2d-P7?|Y=(ol5TDer?dQrc)etl60z5St^NT(%##r7*5{8 z%@4m_`TBfmd=A@**_Ddp%I$Z)nJCSjEq(ggYCg|)-LmFy%@<3v(<=*bbMi`Q{6?v; zurfa*K(DkL&Pz2AY^i}!$-h%nSb4kCDofuysnUUCtd?u_DL%jJbXLikM8Kn1Xw9aT z5pVkLdV+#RhN-*3wJLpCgPib!9jnr3Qa$VXT+8!$gL?sm$!CJ_dsuE>&0i{i_koi= zc5^9zF;TiuSj~^QQ&tZz6=>~{ds9>~sLYsVvjWRD)i%@^%U#A$E<-eWKsD*Tcr5p+ z+Ms?iMMu&E?^g#0i5Bp~ACVpKbo^0XzS!OH@OWTmu9dG}{+I25<8cgq(sr*S z4_ohxVsNKTjSb9~Q!E1w9*pg1v;7;{jAgHFSg2^!dKmOYB{&uJLn2ZGf5o1He8dM! z&D$KZ8-(Tz4SsBX3=T{6R)$*8B|$*e03) delta 351 zcmZoz!_+W^X+nqh>FW8J3{dcZfr*iuk(+^`0Vu!$5saG;q!oa80T44dK-f$S3@jin z5Wr}L2MiN0>+}m2F)FD!fGh?A40CePc3T lU$Nikzgcj~d&Y?d>;O}7Pr(2H diff --git a/MediaControl.ps1 b/MediaControl.ps1 index b253532..98b2f37 100644 --- a/MediaControl.ps1 +++ b/MediaControl.ps1 @@ -39,6 +39,60 @@ public class MediaControl { } "@ +$AimpExePath = "C:\Program Files\AIMP\AIMP.exe" + +function Test-AimpRunning { + param([bool]$Silent = $false) + + $process = Get-Process -Name "AIMP" -ErrorAction SilentlyContinue + if ($process) { + if (-not $Silent) { + Write-Host "检测到媒体播放器进程: AIMP" -ForegroundColor Yellow + } + return $true + } + + return $false +} + +function Invoke-AimpCommand { + param( + [Parameter(Mandatory = $true)] + [ValidateSet("playpause", "next", "prev", "stop")] + [string]$Command, + + [bool]$Silent = $false + ) + + if (-not (Test-Path $AimpExePath)) { + if (-not $Silent) { + Write-Warning "找不到 AIMP.exe: $AimpExePath,将回退到系统媒体控制命令" + } + return $false + } + + $aimpCli = switch ($Command.ToLower()) { + "playpause" { "/playpause" } + "next" { "/next" } + "prev" { "/prev" } + "stop" { "/stop" } + } + + try { + if (-not $Silent) { + Write-Host "通过 AIMP 命令行发送命令: $aimpCli" -ForegroundColor Green + } + Start-Process -FilePath $AimpExePath -ArgumentList $aimpCli -WindowStyle Hidden + return $true + } + catch { + if (-not $Silent) { + Write-Warning "AIMP 命令发送失败,将回退到系统媒体控制命令: $($_.Exception.Message)" + } + return $false + } +} + function Test-MediaPlayerRunning { <# .SYNOPSIS @@ -171,6 +225,15 @@ function Send-PlayPause { param([bool]$Silent = $false) try { + if (Test-AimpRunning -Silent $Silent) { + if (Invoke-AimpCommand -Command "playpause" -Silent $Silent) { + if (-not $Silent) { + Write-Host "命令已发送!" -ForegroundColor Green + } + return + } + } + # 确保媒体播放器正在运行 Initialize-MediaPlayer -Silent $Silent @@ -201,6 +264,15 @@ function Send-NextTrack { param([bool]$Silent = $false) try { + if (Test-AimpRunning -Silent $Silent) { + if (Invoke-AimpCommand -Command "next" -Silent $Silent) { + if (-not $Silent) { + Write-Host "命令已发送!" -ForegroundColor Green + } + return + } + } + # 确保媒体播放器正在运行 Initialize-MediaPlayer -Silent $Silent @@ -231,6 +303,15 @@ function Send-PreviousTrack { param([bool]$Silent = $false) try { + if (Test-AimpRunning -Silent $Silent) { + if (Invoke-AimpCommand -Command "prev" -Silent $Silent) { + if (-not $Silent) { + Write-Host "命令已发送!" -ForegroundColor Green + } + return + } + } + # 确保媒体播放器正在运行 Initialize-MediaPlayer -Silent $Silent @@ -261,6 +342,15 @@ function Send-Stop { param([bool]$Silent = $false) try { + if (Test-AimpRunning -Silent $Silent) { + if (Invoke-AimpCommand -Command "stop" -Silent $Silent) { + if (-not $Silent) { + Write-Host "命令已发送!" -ForegroundColor Green + } + return + } + } + # 确保媒体播放器正在运行 Initialize-MediaPlayer -Silent $Silent @@ -337,4 +427,4 @@ function Main { if ($MyInvocation.InvocationName -ne '.') { # 默认使用静默模式 Main @args -Silent -} \ No newline at end of file +}