Spotify Remote Controller beta

Recommended Posts

Hi. I noticed new MTA version allows specifying headers in fetchRemote, so I could finally implement spotify remote controller (control locally running spotify from the game).

I want to share the possibility with you, so here goes..

This is not ready for public use!

  1. Download https://www.upload.ee/files/7552466/_spotify_.zip.html
  2. Extract [spotify] inside server resources
  3. Start Spotify on same computer where you run the game.
  4. In MTA server, run one of (or all): spotify_cli, spotify_gui, spotify_notifier, spotify_status
  5. In MTA client permanently accept domain access for "open.spotify.com" (this is used anonymously, to get oauth token, MTA client has no spotify session data from you). You might need to reconnect to the server after that as I haven't handled the domain access.


* You might need to change the "starting port" in spotify_api/api.lua, line 42 from 4380 to something else, like 4371 (there currently seems to be a bug with port scanning because on my computer spotify was listening on two ports, both of them responded to version check, but actual status request failed on one of them. Will deal with that definitely if I have some feedback, like which ports people are using and which one is working for them)

* New MTA version has "localhost" whitelisted by default. If it's not you will get prompt to whitelist it.

* Currently spotify_api connects automatically on client resource start, but there is usecase where user alt+tabs out of game, starts Spotify and then we would like to try connecting again. Maybe you have some good ideas how to design the API for that - should it automatically retry connecting (if not connected) on any exported function call? Also, maybe there is good usecase that connecting should not be done on resource start at all and is deferred until really needed. Currently there might be substantial delay finding the correct port though, because fetchRemote timeout argument doesn't seem to have any effect, so the timeout is really slow (around ~1 sec) for each port. In given zip file it's not an issue as it is trying range 4380-4381 :)

Unfortunately, the spotify remote control API that this resource is using, supports only few basic commands: starting specific track (in specific context (context not implemented in my resource yet)), pausing, resuming and getting current status (and track) info. That is all. No seeking, no volume change, no prev/next track (unless you know what is prev and next, and just play those tracks). Nevertheless the existing commands alone are pretty nice to have.

My goal is to publish the spotify_api and let others implement their own usages (either incorporated into gamemode - i.e each map has it's own music; or create some nice GUI controller for the music). Provided spotify_cli and spotify_gui are just dumb interfaces so I know the API is actually working and designed ok.



Provided examples:


Adds commands to play specific track/playlist/album uri; play; pause. Type command 'spotify.commands' to see list of possible commands.


Press 0 (as in zero) to show playlist GUI with play and pause buttons. Click on song name to start playing it.


Permanently shows current playing song and seek position.




Similar to spotify_status, but pops up only for few seconds when new song started and does not include playing time.

Edited by vx89
  • Like 1
  • Thanks 3

Share this post

Link to post

Small update (updated the link in the first post as well). I added support to get periodical updates what's currently playing.

Here is example of the newly added spotify_notifier always showing currently playing track in bottom right corner.


Share this post

Link to post
I can connect more I get errors like 404 play music does not work 

help me this is fantastic

Share this post

Link to post
1 hour ago, Fabioxps said:

I can connect more I get errors like 404 play music does not work 

help me this is fantastic

Hi. Not sure what you are saying, so I'm trying to cover the case where it does *not* connect.

1. Go to https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf and see if controlling Spotify from there works.

2. When Spotify is running, go to start menu and open "Resource Monitor".

In Resource Monitor choose "Network" tab.

In "Listening Ports" section order the table by "Port" column and look if Spotify.exe is running in range 4370-4381. Also if there is anything else running in that range. Let me know.

3. Let's try next steps when we cover the previous ones..

Edited by vx89

Share this post

Link to post
30 minutes ago, Fabioxps said:

In spotify_api/api.lua change connect(4380) to connect(4381).

Looks like when SpotifyWebHelper.exe is running it occupies 4380, so our port scanning finds that 4380 is responding to our status request. However running any actual commands will fail with that 404 error. I will add status command check to make sure the found port is OK.

Edited by vx89

Share this post

Link to post
20 minutes ago, Fabioxps said:

it works

Is it possible to find musics?

Not through this API. You might find the music some other way (e.g to find first 200 songs of a specific playlist or album one could parse https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:3rgsDhGHZxZ9sB9DQWQfuf)  (this is exactly what I will add actually) and use spotify_api just for playback .


Spotify also provides Web API, but it requires user authentication, where user is logged in to spotify.com and your service would prompt spotify.com to ask for a request token to your service for a given user, with user permission. But this can securely happen only inside user web browser. Definitely not MTA, because you have to be logged into spotify.com and there's no safe way to do that inside MTA.

Another way to use Web API is that you authenticate only yourself and searching for songs (with your API key) is always done on server side and just the result is passed on to client-side.

There might be some 3rd party services providing spotify search though.

Edited by vx89

Share this post

Link to post
20 hours ago, Fabioxps said:

How do you find a certain album? example: "Justin Bieber"

https://open.spotify.com/embed?uri=spotify:user:spotify:playlist:  "Justin Bieber"


Unfortunately searching for Justin Bieber is banned on that website.

On more serious note though, that specific website allows only specific spotify uri ids, so no search by names. Only useful part of that website is to get content of specific playlist id; specific album id or specific artist id.

After thinking about it, I think it's actually relatively safe to create a new Spotify account, ask for Spotify Web API token from it, which has no user-specific rights, so you could make that token public (i.e use it directly on client-side) and use Spotify Web API with that token to search for songs. If you will actually try to do it, let me know if that kind of web api user token needs refreshing or it's permanent or if there are any other issues I was not thinking about.

Edited by vx89

Share this post

Link to post

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

  • Recently Browsing   0 members

    No registered users viewing this page.