fix: add public player pause/resume API#295
Conversation
There was a problem hiding this comment.
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 plusstate,currentTime, andtotalTimeto theIPlayer/PlayerAPI, and emitstateChange/endevents. - Export the player interface from the package entrypoint.
- Enable Jest via the shared
ts-jestbase 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.
| 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 { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
Summary
pause()andresume()APIs toPlayerstateChange/endevents@visactor/vstory-coretests and enable package-levelts-jestso the new tests run in CI/hooksTesting
pnpm --dir packages/vstory-core exec jest __tests__/unit/index.test.ts --runInBandpnpm --dir packages/vstory-core exec tsc --noEmit -p tsconfig.jsongit push -u origin issue-294-player-pause-resume(pre-pushranrush test --only tag:packagesuccessfully)Closes #294