Skip to content

fix(audio): handle Howler race condition and add debug mode#276

Merged
test3207 merged 5 commits intomainfrom
fix/android-lockscreen-seekbar-275
Dec 28, 2025
Merged

fix(audio): handle Howler race condition and add debug mode#276
test3207 merged 5 commits intomainfrom
fix/android-lockscreen-seekbar-275

Conversation

@test3207
Copy link
Owner

@test3207 test3207 commented Dec 28, 2025

Summary

Fix Android lock screen seek bar stuck at end position, and add URL-based debug mode for production troubleshooting.

Closes #275

Changes

1. Fix Howler.js race condition (player.ts)

  • Wrap all Howler calls in getState() with try-catch
  • Call howl.duration() only once and reuse result (avoid double-call race)
  • Add isFinite() validation for all returned values
  • Graceful fallback to track metadata duration on error
  • Explicit isLoading/isPlaying fallbacks in catch block

2. Add URL debug mode (logger-client.ts)

Enable verbose logging in production without redeploying:

URL Parameter Effect
?debug=1 All debug/info logs to console
?debug=media Only [MediaSession] logs
?debug=audio Only [Audio] logs
?debug=0 Disable debug mode

Settings persist in sessionStorage for current tab session. Result is cached once per page load for performance.

3. Enhance Media Session logging (media-session.ts)

  • Log position updates with percentage for debugging
  • Log invalid input cases (skipped updates)
  • Upgrade error logs to warn level for prod visibility

Root Cause

TypeError: Cannot read properties of undefined (reading '1')
    at _.duration (audio-vendor-*.js)
    at j.getState (index-*.js)

The syncInterval (500ms) calls audioPlayer.getState(), which accesses howl.duration(id). During track switching, Howler's internal _sounds array may be empty, causing the error.

Testing

  1. Run npm test - all 414 tests pass
  2. Manual test on Android:
    • Open https://m3w.test3207.fun/?debug=media
    • Play music, lock screen
    • Check Console for position logs
    • Verify seek bar shows correct position

Checklist

  • Tests pass
  • No lint errors
  • Backward compatible (debug mode opt-in)

- Wrap Howler calls in try-catch to handle race conditions
- Add URL debug mode (?debug=media) for prod troubleshooting
- Enhance Media Session logging for position updates
- Fix: seek bar stuck at end on Android lock screen

Closes #275
Copilot AI review requested due to automatic review settings December 28, 2025 09:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race condition in Howler.js that caused Android lock screen seek bars to display incorrect positions, and adds a production-friendly URL-based debug mode for troubleshooting.

Key Changes:

  • Wrapped Howler API calls in try-catch to handle race conditions during track switching
  • Implemented URL parameter debug mode (?debug=media, ?debug=audio, etc.) with sessionStorage persistence
  • Enhanced Media Session logging with detailed position updates for debugging

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
frontend/src/lib/logger-client.ts Added URL-based debug mode with filter support and sessionStorage persistence for production debugging
frontend/src/lib/audio/player.ts Added try-catch around Howler calls, eliminated double duration() call, added isFinite() validation, graceful fallback on errors
frontend/src/lib/audio/media-session.ts Enhanced position state logging with percentage display, added invalid input logging, upgraded error logs to warn level

…performance (avoid repeated sessionStorage access) - Use pendingSeek as currentTime fallback in catch block - Simplify null/all filter logic in debug mode - Update media-session comment about sessionStorage persistence - Add debug mode tests
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

- Check isDev first before getDebugMode() to avoid unnecessary calls
- Add isLoading/isPlaying explicit fallbacks in catch block
- Use raw numbers instead of toFixed() in logging (avoid string alloc)
- Document cache invalidation behavior in code comments
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 9 comments.

…ry-catch

- Extract IIFE pattern into shouldShowInConsole() helper function
- Reduce code duplication across 4 debug/info methods
- Wrap howl.state() in try-catch to prevent logging from failing
- Update comments for accuracy (cache behavior, SPA context)
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

- Move window undefined check before cache check to avoid SSR cache pollution
- Move howl.state() call inside try block and reuse result for isLoading
@github-actions
Copy link
Contributor

Coverage after merging fix/android-lockscreen-seekbar-275 into main will be

72.72%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
100%100%100%100%
src/lib
   events.ts100%100%100%100%
   logger-client.ts35.65%28.77%48.48%39.86%101, 101, 101, 101, 101–104, 115, 120, 120–121, 121, 121, 125, 129, 205, 212–214, 214, 214–215, 221, 221, 221–222, 222, 222–223, 225, 247, 252, 257, 257, 257, 259, 259, 259, 261, 263, 263, 263–266, 266, 266, 272, 272, 272–274, 276, 288, 291–292, 292, 292–293, 295, 295, 295, 295–296, 296, 296–297, 301, 307, 307, 311, 311–312, 312–313, 313–314, 314–315, 315–316, 316, 323–324, 324, 324–325, 330, 330, 330, 332–334, 340, 340, 340–341, 344, 363–364, 371–372, 375–376, 381, 383–384, 389, 391–392, 411, 411, 411–414, 418, 426, 426, 426, 430, 437, 440–441, 441, 441, 447–448, 448, 448, 454–455, 455, 455, 460, 460, 460, 462–463, 466, 466, 469, 472–473, 476, 476, 54–56, 56, 56, 61, 61, 61–62, 66, 66, 66, 69–70, 72, 72, 72, 74, 74, 74, 74, 74, 74–77, 80, 80, 80–83, 87–88, 88, 88–90, 93–94
   shared.ts100%100%100%100%
src/lib/api
   config.ts75%62.50%100%85.71%17, 22, 22–23
src/lib/audio
   media-session.ts75.16%90.91%71.43%65.91%109–110, 143, 156–158, 165–167, 169, 176–178, 180, 188–190, 192, 199–201, 203, 219, 233, 247, 260, 268–269, 282, 44–45, 78, 88–89, 95
   queue.ts86.15%82.54%92%86.92%210–211, 223, 225, 225, 225–226, 228, 249–252, 303, 313, 313, 313–314, 316, 37–38, 54–55, 72, 76–77
src/lib/offline-proxy/routes
   libraries.ts42.23%24.32%57.14%51.69%127–128, 213, 253, 266–268, 271, 273, 273, 273–274, 283, 283, 283, 283, 283–284, 293–294, 296, 296, 296–297, 301, 304–305, 308, 310, 310, 310, 312, 316, 316–317, 317, 321, 325, 328, 331, 331, 331–332, 343, 346, 349, 349, 349, 349, 349–350, 352, 357, 361, 364, 366, 369, 369–370, 370–371, 371–372, 372–373, 373–374, 374, 374, 374–375, 375–376, 376, 378, 378, 378, 378, 381, 381, 393–394, 397, 402, 402, 402–404, 404, 410, 420–421, 427–430, 430, 430, 432, 434, 434, 434, 434, 434–435, 445, 448, 450, 455, 66, 95, 95–96
   player.ts47.26%35%57.14%55.70%102, 138, 150–151, 154, 159, 161, 165, 167, 167, 167–169, 171, 171, 171–172, 180, 180–181, 181, 195, 200–201, 207–208, 208, 208–209, 217, 217–218, 218, 231, 236, 259, 280–283, 294, 306–309, 311, 313, 313, 313–314, 314, 314–315, 315, 315–316, 316, 316, 320, 322, 327, 57–59, 59, 59, 59, 59–60, 64–65, 72, 74, 94
   playlists.ts86.27%92.31%91.67%84.35%102, 121, 138, 155, 175, 189, 195–196, 215, 228, 234, 59, 65–70, 72, 89
   songs.ts90.48%75%100%95.24%104, 106, 113, 115, 143–144
src/lib/offline-proxy/utils
   auth.ts93.33%100%100%89.47%70–71
   index.ts100%100%100%100%
   sorting.ts100%100%100%100%
src/lib/storage
   storage-constants.ts100%100%100%100%
src/lib/utils
   audio-filter.ts100%100%100%100%
   defaults.ts100%100%100%100%
   format-duration.ts100%100%100%100%
   format.ts100%100%100%100%
   hash.ts88.24%100%100%85.19%62–63, 84–85
   uuid.ts90%87.50%83.33%93.75%31–32
src/locales
   i18n.ts95.45%87.50%100%97.37%23, 40–41

@test3207 test3207 merged commit ec5a9ad into main Dec 28, 2025
4 checks passed
@test3207 test3207 deleted the fix/android-lockscreen-seekbar-275 branch December 28, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Android lock screen seek bar stuck at end position

2 participants