Jump to content

Need optional methods to 'processexists'


Recommended Posts

I've written a very simple program for the Xsplit community that allows users to add a dynamical "NowPlaying" title to their justin.tv/twitch.tv streams.

Currently this program fetches information from spotify by reading the window title and dumps the title into a textfile which xsplit later on can read.

Now I want to expand the program to supporting multiple media players (winamp, foobar, etc.) but I want to keep the lightness of the application as xsplit really needs every bit of juice available.

Therefor i cannot really use "processexists" to check which media player is running, due to the page faults it seems to trigger.

I can't really read the title to determine what program it is, unless i search for the string "winamp" e.g. in the title. seems somewhat redundant, or is this the best way to go considering the way 'processexists' is working right now?

Any ideas? Below is my program in its current state. Thanks in advance.

While 1
; Fetch Title of Spotify window and remove "Spotify - " from the title
Local $title = StringTrimLeft(WinGetTitle("Spotify"), 10)

; Replace the weird "-" from spotify with a proper dash to separate Artist - Track
Local $final = StringReplace($title, " – ", " - ", 0, 0)

; Open File in overwrite mode - Place the spotify.txt in the same directory as this script.
Local $file = FileOpen("spotify.txt", 2)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

; Write current track to file spotify.txt
FileWriteLine($file, "| " & $final & " |")

; Close file
FileClose($file)

; Sleep for 10 seconds
Sleep(10000)
WEnd
Link to comment
Share on other sites

Try it with ProcessList and then looping through the returned array to find the running player(s) by executable name.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

That's genius! However how will this affect performance running this once every 10 seconds? Should I maybe restrict it to to only do ProcessList until one of the target processes is found?

Link to comment
Share on other sites

It shouldn't affect performance all that much. Once you find one of the processes you're looking for, you can stop looking, unless you want to make sure there isn't more than one instance of it running, or more than one of the targets running at the same time (i.e. 2 WinAmps running, or WinAmp and Foobar running at the same time), then you can keep checking with ProcessExists to see if the target program has stopped running to start your scan again.

You can use ProcessExists with the PID that's returned from ProcessList to check just that window to see if it is still running, rather than just randomly looking for a process called Winamp.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...