5.7 KiB
SoundCloud-Optimized Shaka Player - Change Log
Version: 5.1.0-sc1 (SoundCloud Fork)
Based on: Shaka Player 5.1.0
Fork Date: 2026-06-23
Purpose: Optimize for SoundCloud audio streaming with Widevine DRM
Changes Made
1. Enhanced Stall Detection and Recovery
File: lib/media/gap_jumping_controller.js
Problem: DRM audio tracks would randomly freeze/stall during playback, requiring manual intervention.
Solution: Implemented multi-stage stall recovery with 3 progressive strategies:
Lines 338-365 - Modified onStall callback:
// OLD: Single recovery strategy
if (skip) {
this.video_.currentTime += skip;
} else {
this.video_.pause();
this.video_.play();
}
// NEW: Multi-stage recovery with delays
if (skip) {
// Strategy 1: Skip forward
this.video_.currentTime += skip;
await 100ms
// Strategy 2: Pause/unpause if still stuck
if (readyState < 3) {
pause → wait 50ms → play
}
await 100ms
// Strategy 3: Force buffer refresh
if (readyState < 3) {
currentTime += 0.001
}
} else {
// Similar 3-stage approach for non-skip mode
...
}
Benefits:
- More resilient to transient network issues
- Tries gentler approaches first, escalates if needed
- Better logging with
[SC]prefix for debugging
2. Faster Gap Detection
File: lib/media/gap_jumping_controller.js
Problem: Small gaps at range boundaries would cause brief pauses in playback.
Solution:
Line 241 - Reduced edge detection margin:
// OLD: 0.1 second margin
if (Math.abs(currentTime - info[i].end) < 0.1)
// NEW: 0.05 second margin
if (Math.abs(currentTime - info[i].end) < 0.05)
Benefits:
- Catches gaps 50% faster
- Smoother transitions between buffered segments
- More responsive to stuck playhead at range edges
3. Enhanced Logging
File: lib/media/gap_jumping_controller.js
Problem: Hard to debug SoundCloud-specific playback issues in production.
Solution: Added [SC] prefix to all SoundCloud-related logs:
Lines 346, 349-365 - Stall detection logs:
[SC] Stall detected at 45.23 for 1.5s. Buffered ranges: 3, readyState: 2, paused: false
[SC] Recovery 1/3: Seeking forward 0.1s
[SC] Recovery 2/3: Pause/unpause after seek
[SC] Recovery 3/3: Force buffer refresh
Lines 284-291 - Gap jumping logs:
[SC] Jumping forward 0.15 seconds because of gap starting at 30.45 and ending at 30.60
[SC] Gap detected at range edge: 45.23
Benefits:
- Easy to filter console logs:
[SC] - Detailed state information for debugging
- Clear recovery stage progression
Compatibility
- Shaka Player Version: 5.1.0 (no breaking changes)
- API: 100% compatible with standard Shaka Player
- Browsers: Same as Shaka Player 5.1.0
- DRM: Optimized for Widevine L3 (SoundCloud's DRM)
Build Instructions
# Clone and install dependencies
cd C:\Users\RedLintu16\Documents\Shaka
npm install
# Build the library
python build/all.py
# Output will be in:
# dist/shaka-player.compiled.js
Integration with CrossSound
Option 1: Replace node_modules file
# Run the helper script
cd C:\Users\RedLintu16\Documents\Shaka
.\copy-to-crosssound.ps1
Option 2: Manual copy
# Backup original
cp C:/Users/RedLintu16/Documents/SCSC/node_modules/shaka-player/dist/shaka-player.compiled.js \
C:/Users/RedLintu16/Documents/SCSC/node_modules/shaka-player/dist/shaka-player.compiled.js.backup
# Copy fork
cp C:/Users/RedLintu16/Documents/Shaka/dist/shaka-player.compiled.js \
C:/Users/RedLintu16/Documents/SCSC/node_modules/shaka-player/dist/shaka-player.compiled.js
Testing
Expected Console Output
Normal Playback:
- No
[SC]logs (good sign!)
When Stall Occurs:
[SC] Stall detected at 123.45 for 1.2s. Buffered ranges: 2, readyState: 2, paused: false
[SC] Recovery 1/3: Seeking forward 0.1s
When Gap Jumping:
[SC] Jumping forward 0.08 seconds because of gap starting at 45.67 and ending at 45.75
Test Scenarios
-
Long Playback Session
- Play DRM track for 30+ minutes
- Should see fewer stalls than vanilla Shaka
- Stalls should auto-recover within 1-2 seconds
-
Poor Network
- Throttle network in DevTools (Fast 3G or Slow 3G)
- Track should buffer more aggressively
- Recovery should be automatic
-
Pause/Resume
- Pause track for 5+ minutes
- Resume playback
- Should not start at wrong time
- Should not stall on resume
-
Rapid Skipping
- Skip between tracks rapidly
- No crashes or freezes
- Smooth transitions
Future Enhancements
Phase 2: Audio-Optimized Buffering
- Larger buffers for audio-only content
- Dynamic buffer scaling based on network
- More aggressive prefetching
Phase 3: Better Seek/Resume
- Force currentTime reset on stream switch
- Clear stale buffer state more aggressively
- Improved time validation
Maintenance
To update with upstream Shaka Player changes:
cd C:\Users\RedLintu16\Documents\Shaka
# Add upstream remote (one time)
git remote add upstream https://github.com/shaka-project/shaka-player.git
# Fetch and merge upstream changes
git fetch upstream
git merge upstream/main
# Resolve conflicts in lib/media/gap_jumping_controller.js
# Keep SoundCloud enhancements while merging upstream fixes
Support
For issues specific to this fork:
- Check console for
[SC]logs - Compare behavior with vanilla Shaka Player
- Test with CrossSound's Shaka Player configuration (see SCSC/src/ui/app.js line 518)
For general Shaka Player issues: