Skip to content

AudioManager add suspend#2887

Merged
cptbtptpbcptdtptp merged 7 commits intogalacean:dev/2.0from
GuoLei1990:add-suspend
Jan 28, 2026
Merged

AudioManager add suspend#2887
cptbtptpbcptdtptp merged 7 commits intogalacean:dev/2.0from
GuoLei1990:add-suspend

Conversation

@GuoLei1990
Copy link
Member

@GuoLei1990 GuoLei1990 commented Jan 28, 2026

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

What is the current behavior? (You can also link to an open issue here)

What is the new behavior (if this is a feature change)?

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Other information:

Summary by CodeRabbit

  • New Features
    • Added the ability to explicitly suspend (pause) the global audio context, complementing the existing resume capability so applications can programmatically control audio playback.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 28, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

A new public static suspend() method is added to AudioManager that delegates to the underlying AudioContext.suspend(), returning a Promise<void> and enabling explicit suspension of the global audio context.

Changes

Cohort / File(s) Summary
AudioManager Enhancement
packages/core/src/audio/AudioManager.ts
Added public static suspend(): Promise<void> that calls AudioContext.suspend() and returns a promise resolving when the audio context is suspended

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 I press the hush, the circuits sleep,

A tiny promise folded deep,
The global song takes gentle rest,
Soft thumps of rabbit-heart attest,
Suspended notes in moonlit keep.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'suspend' but the actual method added is 'pause()' that delegates to 'AudioContext.suspend()'—a mismatch between the title and implementation. Update the title to 'AudioManager add pause method' or 'AudioManager add pause() method to suspend audio context' to accurately reflect the public API change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.21%. Comparing base (6a8058b) to head (55d33ba).
⚠️ Report is 1 commits behind head on dev/2.0.

Files with missing lines Patch % Lines
packages/core/src/audio/AudioManager.ts 75.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #2887      +/-   ##
===========================================
- Coverage    83.22%   83.21%   -0.02%     
===========================================
  Files          796      796              
  Lines        90441    90449       +8     
  Branches      9498     9498              
===========================================
- Hits         75274    75271       -3     
- Misses       15085    15096      +11     
  Partials        82       82              
Flag Coverage Δ
unittests 83.21% <75.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GuoLei1990 GuoLei1990 changed the title Add suspend AudioManager add suspend Jan 28, 2026
@GuoLei1990 GuoLei1990 added enhancement New feature or request Audio labels Jan 28, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/core/src/audio/AudioManager.ts`:
- Around line 18-20: AudioManager.pause currently calls
AudioManager._context.suspend() and will throw if _context is undefined; change
pause to either guard and return Promise.resolve() when AudioManager._context is
falsy, or call await AudioManager.getContext() (like resume) to ensure
initialization before calling suspend; update the implementation in the
AudioManager.pause method to reference _context and/or getContext accordingly so
it never dereferences undefined.
🧹 Nitpick comments (1)
packages/core/src/audio/AudioManager.ts (1)

13-20: Consider state management for consistency with resume().

The resume() method handles _needsUserGestureResume flag and deduplicates concurrent calls via _resumePromise. The new pause() method has neither:

  1. If audio is paused via pause(), the visibility change handler may still attempt auto-resume when the tab becomes visible (if _playingCount > 0).
  2. Multiple concurrent pause() calls will each invoke suspend() rather than sharing a single promise.

These may be acceptable trade-offs, but worth considering whether pause() should set a flag to prevent unintended auto-resume.

Comment on lines 18 to 20
static pause(): Promise<void> {
return AudioManager._context.suspend();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Null reference error if pause() is called before audio context is created.

_context is lazily initialized by getContext(). If pause() is called before any audio operations, _context will be undefined, causing a runtime TypeError.

Consider checking if the context exists, or using getContext() for consistent initialization:

🐛 Proposed fix: guard against uninitialized context

Option 1: Return early if context doesn't exist (no-op when nothing to pause)

 static pause(): Promise<void> {
-  return AudioManager._context.suspend();
+  const context = AudioManager._context;
+  return context ? context.suspend() : Promise.resolve();
 }

Option 2: Ensure context is initialized (mirrors resume() behavior)

 static pause(): Promise<void> {
-  return AudioManager._context.suspend();
+  return AudioManager.getContext().suspend();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static pause(): Promise<void> {
return AudioManager._context.suspend();
}
static pause(): Promise<void> {
const context = AudioManager._context;
return context ? context.suspend() : Promise.resolve();
}
🤖 Prompt for AI Agents
In `@packages/core/src/audio/AudioManager.ts` around lines 18 - 20,
AudioManager.pause currently calls AudioManager._context.suspend() and will
throw if _context is undefined; change pause to either guard and return
Promise.resolve() when AudioManager._context is falsy, or call await
AudioManager.getContext() (like resume) to ensure initialization before calling
suspend; update the implementation in the AudioManager.pause method to reference
_context and/or getContext accordingly so it never dereferences undefined.

Copy link
Collaborator

@cptbtptpbcptdtptp cptbtptpbcptdtptp left a comment

Choose a reason for hiding this comment

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

+1

@cptbtptpbcptdtptp cptbtptpbcptdtptp merged commit 362c06b into galacean:dev/2.0 Jan 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Audio enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants