DetermineWhetherToSkip() {
Sleep(1000)
if WinExist("Spotify Free")
and WinExist("ahk_exe spotify.exe")
and WinGetID("ahk_exe spotify.exe") == WinGetID("Spotify Free")
and RunWait("av_checks_v1.exe", , "HIDE") {
SkipViaRestart()
}
}
Which as you can see, runs an exe. This exe uses the following function to determine whether audio is actually playing or not, which in turn uses (a condensed version of) Lexikos' AudioVista library
Now because this was written in AHK v1.1, I compiled it to exe to be called in the main script - because I didn't understand any of it enough to manually convert it, and the convert I found didn't fully work (undeclared vars etc)
But then I realised that I would need to check whether the output is coming from Spotify or another app, as currently, if Spotify is paused the title conditions are met, and if I start playing audio from another window (ie YouTube) but with Spotify open in the background/minimized/whatever, the audio conditions are met and it restarts Spotify, which obviously we do not want. I think I should be able to work out how to check where the audio is coming from using AV (as detailed below)
So, long story short, I need a copy of the AV library for AHK v2. If anyone has a working copy, or can point me in the right direction for converting it, please let me know
Here We discussed about spotify: viewtopic.php?f=76&t=114207
But it is for V1.
Also You can create events when spotify starts and stops playing, but You need to implement interfaces by Yourself.
The above appears to be the relevant lines, however I just get a lot of undefined variable errors (specifically GlobalSystemMediaTransportControlsSession and GlobalSystemMediaTransportControlsSessionPlaybackInfo
I converted it to v2 (using the convert I mentioned earlier) which produced the following:
I ran both the v2 code and the original code (using ahk v1.1) and they both produced similar errors
Do I need to download the data from the GitHub repo mentioned, or add other libraries? Sorry but I have never done system stuff like this before, and consequently have no idea what any of it means sorry :/
Thanks for the relink, I didn't realised the code at the bottom was an addition to the top code (the short replies on that thread make it kinda hard to understand what is what)
I think I am beginning to understand this code now - it looks like the DllCalls and ptr stuff is actually sharing variables between the ahk script and (I'm guessing) Spotify and Windows (and other Dlls)
Whats weird is that, ignoring my attempts at the v2 conversions etc, there are still some issues, namely:
I can run it from source (ie just the code) in the sandbox (I'm using the sandbox here so I don't have to reinstall AHK v1.1 on my pc, as multiple versions of programs generally doesn't end well - idk about AHK specifically tho)
I can run a compiled copy on my pc without any (reported) errors, however the MsgBox just comes up with blank spaces (ie it isnt outputting the variables)
I can run the exact same exe (copy-pasted in) in the the sandbox (ie as the exe, should be fully independent) and it runs perfectly, same as running from source in the sandbox
This would suggest that either the program needs admin permissions, however it shouldn't do as Spotify doesn't need admin permissions to run, and I didn't specify running as admin in the sandbox (normal double-click launch)
Or that it has some dependencies from the v1.1 program that are not present on my pc - but I couldn't find anything besides gdiplus, which I removed all the references I could see to as I don't need the album art for my script
I haven't tried running from source on my pc bc I dont have AHK v1.1 installed anymore and would rather not have multiple versions (for now at least)
The scripts I am using are below, as they are modified from the original ones in your post:
Error: Expected a Number but got an unset variable.
Specifically: hString
064: }
066: {
▶ 068: DllCall("Combase.dll\WindowsCreateString", "wstr", string, "uint", StrLen(string), "ptr*", &hString)
069: }
071: {
Error: Expected a Number but got an empty string.
049: {
050: VarSetStrCapacity(&GUID, 16)
▶ 051: DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", GUID)
052: result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", GUID, "ptr*", &Class, "uint")
053: }
Error: This variable has not been assigned a value.
Specifically: global hString
050: VarSetStrCapacity(&GUID, 16)
051: DllCall("ole32\CLSIDFromString", "wstr", interface, "ptr", GUID)
▶ 052: result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", GUID, "ptr*", &Class, "uint")
053: }
054: If (result != 0)
Error: This variable has not been assigned a value.
Specifically: global result
052: result := DllCall("Combase.dll\RoGetActivationFactory", "ptr", hString, "ptr", GUID, "ptr*", &Class, "uint")
053: }
▶ 054: If (result != 0)
054: {
055: If (result = 0x80004002)
Error: This variable has not been assigned a value.
Specifically: global hString
061: ExitApp()
062: }
▶ 063: DeleteHString(hString)
064: }
066: {
Error: This variable has not been assigned a value.
Specifically: global GlobalSystemMediaTransportControlsSessionManagerStatics
004: app := "spotify.exe"
005: CreateClass("Windows.Media.Control.GlobalSystemMediaTransportControlsSessionManager", IGlobalSystemMediaTransportControlsSessionManagerStatics := "{2050c4ee-11a0-57de-aed7-c97c70338245}", &GlobalSystemMediaTransportControlsSessionManagerStatics)
▶ 006: DllCall(NumGet(NumGet(GlobalSystemMediaTransportControlsSessionManagerStatics+0, "UPtr")+6*A_PtrSize, "UPtr"), "ptr", GlobalSystemMediaTransportControlsSessionManagerStatics, "ptr*", &GlobalSystemMediaTransportControlsSessionManager)
007: WaitForAsync(&GlobalSystemMediaTransportControlsSessionManager)
008: Return
Error: This variable has not been assigned a value.
Specifically: parameter Object
074: }
076: {
▶ 078: AsyncInfo := ComObjQuery(Object, IAsyncInfo := "{00000036-0000-0000-C000-000000000046}")
079: Loop
079: {
Error: This variable has not been assigned a value.
Specifically: global AsyncInfo
079: Loop
079: {
▶ 080: DllCall(NumGet(NumGet(AsyncInfo+0, "UPtr")+7*A_PtrSize, "UPtr"), "ptr", AsyncInfo, "uint*", &status)
081: If (status != 0)
081: {
Error: This variable has not been assigned a value.
Specifically: global status
079: {
080: DllCall(NumGet(NumGet(AsyncInfo+0, "UPtr")+7*A_PtrSize, "UPtr"), "ptr", AsyncInfo, "uint*", &status)
▶ 081: If (status != 0)
081: {
082: If (status != 1)
And incase it is relevant, here is the Windows version info from both machines:
Last edited by gregster on 25 Mar 2023, 04:34, edited 1 time in total.
Reason:Removed img-tags/fixed broken links. You can only use those tags with direct image links.