Sam El-Husseini
Published © MIT

Microbit + Spotify (Windows)

Pause/resume your Spotify playlist with a micro:bit on Windows.

BeginnerFull instructions provided1 hour10,806
Microbit + Spotify (Windows)

Things used in this project

Story

Read more

Code

microbit-spotify-windows.js

JavaScript
var SerialPort = require("serialport");
const Readline = SerialPort.parsers.Readline;

const SpotifyWebHelper = require('spotify-web-helper');
const spotify = SpotifyWebHelper({'port': 4381});

var port = new SerialPort('COM7', {
 baudRate: 115200,
 autoOpen: false
})
const parser = new Readline();
port.pipe(parser);

spotify.player.on('ready', () => {
    console.log("Spotify ready")
    port.open(() => {
        console.log("Port open");
        parser.on('data', (data) => {
            console.log('Received Data: ' + data.toString());
            processData(data);
        });
    })

    function processData(data) {
        if (data.indexOf('PLAY') == 0) {
            // Handle PLAY received
            spotify.player.pause(true);
        } else if (data.indexOf('PAUSE') == 0) {
            // Handle PAUSE received
            spotify.player.pause(false);
        }
    }
});

Credits

Sam El-Husseini

Sam El-Husseini

1 project • 8 followers
Working on MakeCode at Microsoft, micro:bits, Circuit Playground Express, and Minecraft.

Comments