Skip to content

fix: add public player pause/resume API#295

Merged
xile611 merged 3 commits intodevelopfrom
issue-294-player-pause-resume
Apr 8, 2026
Merged

fix: add public player pause/resume API#295
xile611 merged 3 commits intodevelopfrom
issue-294-player-pause-resume

Conversation

@xile611
Copy link
Copy Markdown
Contributor

@xile611 xile611 commented Apr 3, 2026

Summary

  • add public pause() and resume() APIs to Player
  • expose playback state, current time, total time, and stateChange/end events
  • add @visactor/vstory-core tests and enable package-level ts-jest so the new tests run in CI/hooks
  • document the new player APIs in the English and Chinese guides

Testing

  • pnpm --dir packages/vstory-core exec jest __tests__/unit/index.test.ts --runInBand
  • pnpm --dir packages/vstory-core exec tsc --noEmit -p tsconfig.json
  • git push -u origin issue-294-player-pause-resume (pre-push ran rush test --only tag:package successfully)

Closes #294

Copy link
Copy Markdown
Contributor

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 adds a public playback control surface to @visactor/vstory-core’s Player, allowing consumers to pause/resume playback, query playback state/timing, and subscribe to lifecycle events without touching private internals (addressing #294).

Changes:

  • Add pause() / resume() APIs plus state, currentTime, and totalTime to the IPlayer/Player API, and emit stateChange/end events.
  • Export the player interface from the package entrypoint.
  • Enable Jest via the shared ts-jest base config and add unit tests for the new behavior; update EN/ZH guides.

Reviewed changes

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

Show a summary per file
File Description
packages/vstory-core/src/interface/player.ts Extends the public player interface with pause/resume, state + timing getters, and event payload types.
packages/vstory-core/src/index.ts Re-exports the player interface/types from the package entrypoint.
packages/vstory-core/src/core/player.ts Implements pause/resume, state tracking, ticker listener attach/detach, and stateChange/end emissions.
packages/vstory-core/jest.config.js Switches to the shared Jest base config and adds package-local setup mocks.
packages/vstory-core/tests/unit/index.test.ts Adds unit tests covering pause/resume behavior and end-state/event emission.
docs/assets/guide/zh/tutorial_docs/VStory_Concepts/story-player.md Documents the new player pause/resume, state/time accessors, and events (ZH).
docs/assets/guide/en/tutorial_docs/VStory_Concepts/story-player.md Documents the new player pause/resume, state/time accessors, and events (EN).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 129 to 140
play(loop: number = 0) {
const totalTime = this._scheduler.getTotalTime();
const totalTime = this.totalTime;
this._loop = loop;
this._currTime = 0;
this._lastFrameTime = -1;
this._attachTickerListener();
this._setState('playing');
if (totalTime <= 0 && !this._loop) {
// 没有动画,且不循环也不持续,直接定位到0s
this._currTime = 0;
this.tickTo(0);
this._finishPlayback();
} else {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

play() resets _currTime to 0 without clearing scheduler/story state. If play() is called again after any prior progress (e.g., after an ended run or after pausing mid-way), Scheduler will still have _runnedAct/_applyedAppearAct populated, so actions/appear initialization won’t run for the restarted timeline. Consider resetting state when starting playback (e.g., call reset()/_scheduler.clearState() + story reset, or call tickTo(0) before mutating _currTime so the existing rewind-reset path runs).

Copilot uses AI. Check for mistakes.
Comment thread packages/vstory-core/src/core/player.ts
Copy link
Copy Markdown
Contributor

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 7 out of 7 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xile611 xile611 merged commit 19a364f into develop Apr 8, 2026
9 of 11 checks passed
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.

Feature Request: Add pause() and resume() public API to Player

3 participants