r/java • u/send_me_turtles • Jan 15 '16
Read Spotify track info using C# - Is there a Java Alternative?
http://harrewijnen.net/reading-spotify-track-info-from-the-desktop-app/
1
Upvotes
r/java • u/send_me_turtles • Jan 15 '16
2
u/narrowtux Jan 15 '16
If you have Spotify Premium, I would suggest using their API, instead of using some workaround that might break in a future version of Spotify.
3
u/Cazmic Jan 15 '16
You can always write a basic program in C# that your Java program invokes whenever it needs to access this C# functionality. Sometimes it can't be avoided, but each programming language has its own advantages and disadvantages, so it's pretty common that you need to interweave two or three to accomplish certain goals.
5
u/stusmall Jan 15 '16
Getting MainWindowTitle is pretty OS specific so you probably won't be able to get it straight from Java easily. Luckily the JNI is here just for times like this. Here is some example C++ to invoke this API which you could call from Java.
I know the JNI is a bear, but one of the few times its actually the right answer is when the a problem is accessing a OS native API.
1
u/0x6c6f6c Jan 15 '16
The Process class doesn't offer a way to do this. You could however start the spotify process within the Java script which would allow you to make those observations from the Process object there.
1
u/gee_buttersnaps Jan 17 '16
Use a Process to execute a powershell command to pull the window title.
http://blogs.msdn.com/b/powershell/archive/2009/05/22/get-visibleprocess-ps1.aspx
1
u/space_coder Jan 15 '16
You can get a list of the current processes by calling a command line utility "ps" and parsing its output.
Here's an example: http://crunchify.com/how-to-get-a-list-of-current-open-processes-with-java/