Introduction: Albums With NFC Tags to Automatically Play Spotify Music on Chromecast

This project started with the idea of making an album collage of my most played artists on Spotify. After some playing with the Spotify API in Python, I thought it would be nice to link these album covers to their Spotify URI's and start playing them by simply touching them with my phone. The automation app allows to automatically play the touched albums on a Chromecast device.

Step 1: What You Will Need

  • NFC tags: As many programmable tags as you have albums you want to display. (Better buy some more as you can never have to many NFC tags at home) I bought mine in bulk from AliExpress (100 tags for about 10 $ ).
  • An android phone with NFC
  • NFC TagWriter by NXP, a free android NFC writer application

  • Automate, a free android automation application to automate actions

  • A Spotify account. This project was written to be used with Spotify: a Spotify URI ( Uniform Resource Identifiers for sharing and locating artists, albums, searches, playlists and songs within the Spotify library) is written on a NFC tag and later on read by Automate to start playing music on Spotify (and possibly cast to your Chromecast).

  • (Optional) A Chromecast device. If you have no device to cast to, the music will simply start playing on your smartphone.

  • (Optional) Album covers: you can use album covers you already have at home. I did not have any album covers as all my music is streamed from Spotify so I downloaded the album covers with the Python script from step 2a and printed them as non-glare pictures at 10 cm x 10 cm.

Step 2: Getting Album Covers and Spotify URI's

There are two ways you can obtain the album covers and Spotify URI's:

  • Step 2a explains how you can automatically download the album covers of your top artists in Spotify using a Python script I wrote. This script also automatically generates the necessary .csv file with all the Spotify URI's to the albums on Spotify. This .csv file is needed in step 3 to write the NFC tags.
  • Step 2b explains how you can obtain album covers and Spotify URI's manually without running Python scripts and installing Python packages. This step is simpler but is a lot of work if you have to download multiple album covers manually, search for every URI yourself and copy and past them into the necessary .csv file.

Step 2a: Automatically downloading album covers and Spotify URI's with a Python script

In this step 10 album covers of each of your 60 most played artists on Spotify are automatically downloaded by a Python script I wrote. At first the Python package Spotipy should be installed on your PC. On systems with pip installed this can be done by:

$ pip install spotipy

The Python script can be found on my Github as You run the script from a terminal or command prompt as:

$ python <Spotify_username>

The first time you run the script a link will be opened in your default browser to give the script access to read your Spotify "user-top" statistics. After giving the application access, you are directed to a link starting with Copy the whole link and paste it in the terminal or command prompt to give the script the necessary permissions. Hereafter the program downloads 10 album covers per artists into the folders Covers/<artist_name/ It is for you to decide which albums you want print for your collage and which you want to discard. I printed mine as 10 cm x 10 cm non-glare pictures at an online photo printing service for about 0.10 EUR apiece. Besides album covers, also a .csv file is generated containing all the Spotify URI's of the albums downloaded. This .csv file is named TagWriter_mass_encoding.csv and is already formatted to use in the TagWriter application to easily write multiple NFC tags. It is strongly recommended to remove all rows of albums that you did not print and do not want to write an NFC tag for. If there are album covers that you printed which were not downloaded by the Python script, look at step 2b to manually add the Spotify URI to the .csv file.

Step 2b: Manually downloading album covers and finding Spotify URI's

If you do not want to use the Python script to automatically download album covers of your top artists on Spotify, follow this step. With a simple Google image search you can find all the album covers you want to print. I printed mine as 10 cm x 10 cm non-glare pictures at an online photo printing service for about 0.10 EUR apiece. You also need to search for every album the Spotify URI. This is done in the Spotify desktop app as can be seen in the print screen. Select the album options and go to share>'Copy Spotify URI'. The Spotify URI should be added to a .csv file which is formatted especially for the TagWriter app which we will use to easily write multiple NFC tags. A template with some example data is presented in the screenshot and can be downloaded on my Github page as Tagwriter_mass_encoding.csv. Be sure to fill in this template with your Spotify URI's and a meaningful description. When ready, save this file again as a .csv file.

When you have printed your album covers, place one NFC tag on the back of every album cover. It is best to place the NFC tags at the same position on the albums in order to read the tags more easily.

Step 3: Writing Spotify URI's With TagWriter

The Tagwriter_mass_encoding.csv file will be used as an input for the NFC TagWriter by NXP android app. Please install this app on your NFC android phone via the Google Play Store. The Tagwriter_mass_encoding.csv file should be stored on your smartphone for the application to access it. To write the NFC tags from the .csv file follow the next steps:

  1. In the home screen of the TagWriter app select 'Write Tags"
  2. Select "Write from CSV"
  3. Go to your .csv file and select it by LONG pressing the file
  4. At the top right you see Dataset index (1/6). This means that the application correctly read the 6 entries in the .csv file (see the screenshot in step 2b for the 6 entries in the template). Select "Write"
  5. In the next screen you see the content of the current item. In the screenshot this is "spotify:album:32MqLe..." which corresponds to the first entry in my Tagwriter_mass_encoding.csv template. This entry has the description White Lies: BIG TV so this content should be written to the tag on this album cover.
  6. Bring your phone to the NFC tag to write the spotify URI to the tag. When the tag is perceived by your NFC chip, it will be written automatically. The NFC chip of your smartphone should be very close to the chip in order to do this. If this does not happen easily, do a Google search to find the exact location of the NFC chip on your device.

Step 4: Using Automate to Start Playing Music by Smartphone Touch

Automate is an automation app like Tasker but it uses a more intuitive flow diagram approach and has a completely free version. I already wrote the flow for this project so you only need to import the flow into the app and change some settings to your configuration. The flow can be downloaded from within the Automate app by selecting the community icon in the upper right corner and searching for "Spotify album from NFC tag to Chromecast". The flow diagram is presented in the screenshot above. You will need to change some blocks for your Chromecast and Spotify app configuration:

  • The upper left variable block: in the English version of the Spotify app the available devices are presented under a text element named "Devices Available". If your app is in another language, change the value of this block.
  • The next block: Here the name of your Chromecast device is stored. If yours is different from "Living room", change the value of this block.
  • If you have a slower Android device: try changing the time of the delay blocks in order to get the correct click interactions.
  • If you only want to play music on your device and not cast to Chromecast: remove the output flow line from the bottom "Delay 3s" block.

When running this flow in the background, you should be able to play the album on your smartphone or Chromecast by simply touching the album cover at the NFC tag location. If something does not work correctly, look at the Logs of the Automate flow.

Step 5: Remarks

  • I placed about 45 album covers in a large frame (100 cm x 60 cm). Against my expectations the NFC tags were easily read behind the small glass plate.
  • The Spotify URI's of playlist are also supported by the Automate flow. You can look for the Spotify URI of your favorite playlists and write them on a TAG in the same way as the previous steps.
  • The Spotify API does not allow to query a user's most played albums. That is why first the most played artists are queried and then the album covers of the 10 top albums of that artist are downloaded .
Audio Contest 2018

Participated in the
Audio Contest 2018