I’m building a wellness platform where practitioners and their clients have video sessions together. I want to add a feature where practitioners can link their Spotify accounts to play background music during sessions. The tricky part is that clients don’t have Spotify accounts but still need to hear the same music that’s playing for the practitioner.
Is there a way to sync audio playback so both users hear identical tracks at the same time? The practitioner would be logged into Spotify and select playlists, but the client side wouldn’t have any Spotify authentication.
I tried getting the track URL from Spotify after practitioner login and feeding it to the client’s audio player, but this approach failed. Our platform uses React with TypeScript on frontend and Spring Boot for backend. Most clients use mobile devices with Safari browser, so the solution needs to work across different platforms.
Any suggestions for implementing synchronized music streaming between authenticated and non-authenticated users?
You’re running into Spotify’s terms of service - they explicitly ban redistributing audio streams to unauthorized users. Even if you extract track URLs, they’re token-based and tied to specific sessions, so it won’t work. I’ve tackled similar real-time audio sync projects. Skip the platform restrictions and use a neutral music source instead. Check out Epidemic Sound or AudioJungle - they’ve got APIs for commercial use. For syncing, set up a simple message queue. When the practitioner hits play, pause, or seeks, broadcast those events to all clients with timestamps. Keep everyone on the same playback state and add some network latency compensation. The real pain point? Mobile Safari’s autoplay restrictions. You’ll need explicit user interaction before any audio starts playing. WebRTC’s probably overkill here since you’re not doing true peer-to-peer streaming - just coordinated playback of the same content.
I ran into this exact problem building a collaborative streaming feature. Spotify’s API won’t let you stream tracks to users who aren’t authenticated - it’s a licensing thing. But there are ways around it. What worked for me was setting up a server-side audio relay. Your Spring Boot backend authenticates with Spotify, grabs the audio stream, then pushes it out to clients via WebSocket or WebRTC. You’ll need to handle audio buffering and sync timestamps so both users hear the same thing at the same time. You could also try YouTube Music API or SoundCloud - they’re more flexible for this kind of setup. Some devs have luck using Web Audio API to capture and rebroadcast streams, but watch out for browser compatibility issues, especially Safari on mobile. Bottom line: make your server an audio proxy that connects authenticated and non-authenticated users while staying compliant with licensing.