Detailed Setup Guide
This guide covers everything you need to set up Player2, from Spotify Developer credentials to deployment.Spotify Developer Setup
Creating a Spotify App
Access Spotify Developer Dashboard
Navigate to the Spotify Developer Dashboard and log in with your Spotify account.
Create New App
Click “Create App” and fill in the required information:
- App Name: Player2 (or your preferred name)
- App Description: Enhanced Spotify music player with lyrics
- Redirect URI:
http://localhost:5173 - API: Select Web API
For production deployments, add your production URL (e.g.,
https://yourdomain.com) to the Redirect URIs list.Environment Configuration
Required Environment Variables
Player2 uses Vite’s environment variable system. Create a.env file in your project root:
.env
Vite requires environment variables to be prefixed with
VITE_ to be exposed to the client-side code.Environment Variable Reference
| Variable | Required | Description | Example |
|---|---|---|---|
VITE_SPOTIFY_CLIENT_ID | Yes | Your Spotify App Client ID | 16d98594b10949eb9aed4628a58b37e8 |
VITE_SPOTIFY_REDIRECT_URI | Yes | Redirect URI for OAuth | http://localhost:5173 |
Loading Environment Variables
Player2 loads these variables in the SpotifyContext:src/contexts/SpotifyContext.tsx
Project Structure
Key Directories and Files
Core Components
Spotify Context Provider
TheSpotifyContext manages all Spotify-related state and functionality:
SpotifyProvider usage
Available Context Values
Context API
Key Features Implementation
Real-Time Lyrics
Lyrics are fetched from LRCLIB with intelligent caching and prefetching:Lyrics implementation
Lyrics are cached in memory to prevent redundant API calls. The next track’s lyrics are prefetched 10 seconds before the current track ends.
Dynamic Color Extraction
Album art colors are extracted using ColorThief and applied to the UI:Color extraction
Keyboard Shortcuts
Keyboard controls are implemented for quick playback control:Keyboard controls
Development Workflow
Available Scripts
package.json scripts
Development Server
Start the development server with hot module replacement:http://localhost:5173 by default.
Linting
Run ESLint to check for code quality issues:Building for Production
Creating an Optimized Build
Build Output
The production build is optimized with:- Code splitting - Smaller initial bundle size
- Tree shaking - Removes unused code
- Minification - Compressed JavaScript and CSS
- Asset optimization - Optimized images and fonts
Deployment Options
Vercel
Add Environment Variables
In your Vercel dashboard, add:
VITE_SPOTIFY_CLIENT_IDVITE_SPOTIFY_REDIRECT_URI
Netlify
Static Hosting
Deploy thedist/ folder to any static hosting service:
- AWS S3 + CloudFront
- GitHub Pages
- Firebase Hosting
- Cloudflare Pages
Troubleshooting
Common Issues
Build Errors
Build Errors
If you encounter build errors:
-
Delete
node_modulesand reinstall: -
Clear Vite cache:
-
Check Node.js version (requires v16+):
CORS Issues
CORS Issues
If you see CORS errors with Spotify API:
- Verify your Redirect URI matches exactly
- Ensure you’re using
http://localhost:5173(not 127.0.0.1) - Clear browser cache and cookies
Lyrics Not Loading
Lyrics Not Loading
If lyrics don’t appear:
- Check browser console for LRCLIB API errors
- Verify the track has synchronized lyrics available
- Check network tab for failed requests
Color Extraction Fails
Color Extraction Fails
If colors aren’t updating:
- Check if album art URL is accessible
- Verify CORS headers allow image loading
- Check console for ColorThief errors
Advanced Configuration
Customizing Vite Config
Modifyvite.config.ts for advanced build options:
vite.config.ts
TailwindCSS Configuration
Customize the design system intailwind.config.js:
tailwind.config.js
Next Steps
Back to Introduction
Learn more about Player2’s features
Quick Start
Get started quickly