Spotify Custom Tile

This is a proof-of-concept for integrating Spotify in a Custom Tile.

:warning: The Spotify Web API is limited in many ways compared to their apps. It will only show devices which are ‘active’ and controllable. Check out this post for more details.

:man_technologist: This is one of several sample tiles that were built as part of the Custom Tiles release and is not intended to be a fully polished tile. Please feel free to learn from it, copy from it, or play with it.

image

If you’d like to give it a quick try, you can use my demo app for authorizing your Spotify account (can be revoked anytime), but please note that I am not actively maintaining the authorization app as it’s just for this demo purpose.

Setup

  1. Go to https://spotify-demo-auth.glitch.me, and follow the instructions to authorize this demo app to access your Spotify account and take a note of the Refresh Token.

  2. Tap the import button above to import the Spotify Custom Tile into your SharpTools account.

  3. Tap Preview at the bottom of the editor and enter the Refresh Token from the first step.

  4. Tap on the available devices button image to select a device first then select the desired playlist to play.

:information_source: Please note that this demo code uses Spotify Web APIs, and some of the player control APIs, such as play/pause, skip and prev, require the Spotify Premium account. See Spotify Web API Reference for more details.

Detailed Steps:

The source code and detailed steps for creating your own Spotify app and retrieving access token and refresh token can be found here, and please note that this is just a proof-of-concept/demo, and is not an official integration.

3 Likes

@James Pretty Cool! I followed the steps and have the custom tile on a dashboard. It pulls up my playlists and devices however, it won’t actually let me select a playlist or play anything. Any thoughts? Am I supposed to do something with the Access Token?

HI @Clayton_Rudney, did you select a device by clicking on the available device button first? This demo code doesn’t pre-select a device, so you will have to choose which device you want to it to play first.

2021-04-29_17-12-01

@James Thanks for this reply. I was having the same issue. Per your suggestion, I was able to add devices through the Spotify app and can now see what’s playing. However, I can’t seem to interact with the controls (e.g. pause, skip, channel, device, etc.). I know that this is only a demo, but it’s really exciting to see this come to fruition.

@Jordan_Coffey, that’s interesting. If you can see the playlists and available devices in the tile, the Spotify token should have the access to control the play state as well. Does the playlist and available device buttons work for you?

Can you press F12 in the browser to open the developer tool to see if there’s any error when pressing the control buttons?

The available device button works (i.e., it shows the appropriate list of available devices and this list refreshed as I added devices) as does the playlist button (i.e., it shows playlists from my iTunes library as included in Spotify). In looking at the console, I am seeing the following errors as I click the controls:

Error: Request failed with status code 403
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
onreadystatechange https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
promise callback*r.prototype.request https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
exports https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js:2
controlPlayer https://run.sharptools.app/custom-tile/TGAt5oIiwxBht5KCp04R/?renderToken=XXXXX:404
onclick https://run.sharptools.app/custom-tile/TGAt5oIiwxBht5KCp04R/?renderToken=XXXXXX

I’m using Chrome. When I select one of my devices I get the following message:

Active Device: ?renderToken=XXXX Active Device:

Then it takes me back to my playlists.

Error: Request failed with status code 404 ?renderToken=XXX
at e.exports (isAxiosError.js:10)
at e.exports (isAxiosError.js:10)
at XMLHttpRequest.l.onreadystatechange (isAxiosError.js:10)

Then it says no active device.

@James figured out part of the problem. I’m using Windows 10. I didn’t have the spotify app installed. Once I did, it allowed to play on my PC. However, it won’t let me select an amazon echo device and play there. It keeps defaulting back to my PC.

@Clayton_Rudney, thanks for the updates. I will have to test it against to the echo devices. I tested it for my desktop and phone, but didn’t have this issue. Almost seems like it doesn’t have access to the device (or the device is not found).

@Jordan_Coffey, I’d hesitated to guess it’s the same issue for your case that it is able to pull your playlist and available devices, but doesn’t have the control to the selected device for some reason. Can you try to install the Spotify app on your PC/Mac or on your mobile devices to give it a quick try?

I will look into this later.

Thanks @James. Uninstalled the app on my phone as well as logged out on my computer. Same issue. Playlists and devices update. Album art and track information updates. Just can’t seem to send commands to Spotify. Again, I know that this is a proof of concept so I appreciate your willingness to even respond. Just the concept of this functionality indicates so much progress and so many new opportunities!

3 Likes

Agreed! I really appreciate the support. This functionality really ramps ups the usability of Sharptools. Amazing work!

1 Like

@Clayton_Rudney & @Jordan_Coffey, the issue seems to be related to the Spotify API restriction that some Player APIs, such as play/resume, skip, prev, require the Spotify premium account, and some others, like getting available devices and playlists, don’t. I’ve added this note in the top post to help clarify this, and updated the source code to better inform users via the toast message when having issues sending Spotify requests.

Thanks for the kind words and yes this Custom Tile feature really enables a lot more interesting integration opportunities, and I cannot wait to see what the community will come up with. :grin:

Hey James,

I am experiencing the same issue. I’m able to control Spotify on my mobile and PC with this, but not my Echo devices. I do have a Spotify Premium account, so think this should work? If there’s any info I can provide to help, let me know.

This custom tile is awesome, thank you so much!

Hi @James_Morrow welcome to the community. That’s weird. I’ve tested both my 1st gen Echo and Echo Dot, and I wasn’t able to reproduce this issue. Can you please verify if you are using the latest code by tapping the gear icon at the top-right corner in the code editor in Custom Tile editor, select “Update from Source”, then scroll down and press Save?

I’ve added some additional troubleshooting information and would like to see what error you receive when controlling your echo devices.

It would be a great help if you can PM me and send the screenshots/videos of the errors you see, errors in the browser’s Developer Tool’s console, and the steps how you reproduce it.

Here is a quick test using my 1st gen Echo and Echo Dot.
2021-05-01_08-55-19

Sorry guys as I am very new to this but, I did find that if I used my Spotify App to connect to a device, Echo Show 5, and play music through it, I could then choose that Echo Show 5 in the custom tile. But if I tried to connect to a device that my native Spotify app has NOT connected too, it wouldn’t work.
I really hope that my help.

2 Likes

I followed what @dustin_davis said and sure enough, one by one, each device started working from the customer tile. Thanks!

Bit odd as I’d definitely connected to the via the Spotify app in the past, but not since initially adding the custom tile.

Edit: FYI before following these steps, I would select the device, then some music and get the error:
image

1 Like

@dustin_davis, @James_Morrow I think I might have found the device selection bug and updated the code to include the user playback transfer when a device is selected. Can you guys update from the source code and give it a try?
image

@James @James_Morrow, I just updated from source code and everything seemed to work just fine. I did notice that some of my devices are not showing my device name instead I get this


Is that just something on my end?

@dustin_davis what devices are they? (Those showed device “id” instead of device name.)
When this issue occurs again, can you please follow the instructions below and send the results for further troubleshoot?

1.Go to https://spotify-demo-auth.glitch.me/ again
2.Tap Step 1: Authorize (You should not be asked to agree to authorize the demo app again because you already done that, but if it asks you again, clicks ok.)
3.Tap Step 2: Get Token
4. If the tokens are received correctly, you should see the optional test option below.
5. Click on Get Available Devices and copy the complete results
6. Send me the results from the previous step along with a screenshot of your Spotify demo tile.

Thanks.

Hi- Thanks for creating this, it looks great so far! I am having a few problems that I’m hoping you can help me with.

1- When I try to change tracks it says I need a spotify premium account, but I already have one.
2- Not all of my available devices show up, about 2 of the 20 that I have.
3- I’m trying to update your code and put in an access token, but those options dont exist within the custom tile editor

Thanks!