This was my first time using Godot! (I've been a long time user of unity)
I probably should've started with something a little more focused on learning Godot itself and exploring what the engine has to offer...
Instead, I got sidetracked and made BelPet, a small desktop pet that chills on your screen and doubles as a Spotify player :D
What is BelPet?
BelPet is a desktop pet built with Godot 4 and C#.
You can drag Bel around your desktop, and he falls back down and rests above your taskbar. More importantly, he can act as a Spotify playback device.
From Bel, you can:
- Play and pause your music
- Skip to the next or previous track
- Seek through the current song
- Scroll over Bel to change the volume
- See the currently playing album artwork
- Drag him around your desktop
The goal was basically to have a tiny Spotify controller living on my desktop rather than having to constantly open Spotify.
My First Time Working With a Public API
This was also my first time building something that communicates with a public API/SDK, which ended up being one of the most interesting parts of the project.
BelPet uses both the Spotify Web API and Spotify Web Playback SDK, but they serve slightly different purposes.
When BelPet is the active Spotify playback device, the Web Playback SDK handles the playback itself.
When another device is active, BelPet can instead poll the Spotify Web API periodically to retrieve information such as the current song, playback progress, volume and playback state.
This lets the UI stay synchronized even when Spotify is playing somewhere else.
Getting the Web Playback SDK Into Godot
One of the more interesting problems was that Spotify's Web Playback SDK is a JavaScript SDK intended to run in a browser.
My application, obviously, isn't a browser.
I ended up using godot_wry to embed a WebView inside the application. The WebView runs a small HTML/JavaScript page containing Spotify's Web Playback SDK, while the rest of BelPet runs normally in Godot/C#.
It was definitely a lot further down the rabbit hole than I expected to go for my first Godot project LOL.
Making Godot Behave Like a Desktop Pet
The other fun part was making a Godot game window behave less like a game window and more like something actually living on the desktop.
BelPet uses a transparent, borderless, always-on-top native window.
I also added custom mouse passthrough regions so that the transparent parts of the Godot window don't block you from clicking applications underneath it.
Bel itself remains clickable and draggable while the empty space around him behaves like there isn't a window there at all.
There's also some simple gravity so when you let go of him, he falls until he reaches the usable bottom of the desktop above the Windows taskbar.
None of these things were particularly huge individually, but putting them together taught me quite a lot about how Godot interacts with the actual OS rather than just what happens inside the game viewport.
Then I Discovered Spotify's Development Restrictions...
Unfortunately, I only realized this when I was already mostly finished with the project ðŸ˜
Spotify places restrictions on applications running in Development Mode.
BelPet works normally when BelPet itself is selected as the active Spotify playback device.
I had also built BelPet to monitor and control Spotify while another device — such as your phone or desktop Spotify client — is the active player. However, that functionality relies on Spotify's Web API, and accounts need to be authorized for my development application.
Obviously, manually adding everyone who downloads a random GitHub project isn't really practical.
There is a workaround: you can create your own Spotify developer application, put your own Client ID into BelPet and build it yourself.
Also, Spotify Premium is required for BelPet.
Because of these restrictions, I've decided not to develop the project much further for now.
What I Originally Wanted to Add
I actually had more planned.
One of the larger features I wanted was an album catalogue built directly into BelPet.
Instead of Bel only controlling whatever you're already listening to, you'd be able to browse your albums/playlists and start music without opening Spotify at all.
There were also plenty of smaller things I could've done to make Bel feel more like an actual desktop companion rather than primarily a Spotify controller.
But considering the API limitations, I think this is a decent stopping point for the project.
What I Learned
Despite getting very sidetracked from my original goal of simply "learn Godot", I'm pretty happy that I did.
This one small project ended up exposing me to:
Godot 4 with C#
Communicating with REST APIs
OAuth authentication
Spotify's Web API
Spotify's Web Playback SDK
Communication between C# and a browser-based SDK
Embedding a WebView in Godot
Native window manipulation
Mouse passthrough
Packaging all of this into an actual desktop application
So... maybe not the most sensible first Godot project, but definitely a fun one :D
The project is completely open source under the MIT License if anyone wants to look through it, mess around with it, or build upon it.
Top comments (0)