Skip to content

feat: add player and composition play/pause/resume events #1079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feat/2.6
Choose a base branch
from

Conversation

yiiqii
Copy link
Collaborator

@yiiqii yiiqii commented Jul 15, 2025

#1075

Summary by CodeRabbit

  • New Features

    • Added new playback event notifications, including 'play', 'pause', and 'resume', for both player and composition objects.
    • Enhanced event logging in the interactive demo to reflect playback state changes with time information.
  • Refactor

    • Simplified playback state tracking by removing internal flags and relying on actual playback states and explicit event emissions.

@yiiqii yiiqii requested a review from wumaolinmaoan July 15, 2025 07:24
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

Walkthrough

The changes introduce explicit 'play', 'pause', and 'resume' event emissions in the playback control logic across the composition, player, and display object classes. Event types are updated to support these notifications, and demo code now logs these events. Internal state tracking is simplified by removing redundant flags.

Changes

File(s) Change Summary
packages/effects-core/src/composition.ts Added 'play' and 'pause' event emissions to playback control methods; adjusted internal pause logic.
packages/effects-core/src/events/types.ts Extended CompositionEvent type with 'play' and 'pause' events; removed commented-out line.
packages/effects-threejs/src/three-display-object.ts Modified resume method to emit a 'resume' event before resuming compositions.
packages/effects/src/player.ts Removed autoPlaying flag and handleResume method; now emits 'play', 'pause', and 'resume' events based on actual playback state.
packages/effects/src/types.ts Added 'play' and 'resume' event types to PlayerEvent.
web-packages/demo/src/interactive.ts Added event listeners for 'play', 'pause', and 'resume' on player and composition, with logging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Player
    participant Composition
    participant DisplayObject

    User->>Player: play() / gotoAndPlay()
    Player->>Composition: play() / gotoAndPlay()
    Composition-->>Player: emits 'play' event (with time)
    Player-->>User: emits 'play' event (with time)
    Note over Player,Composition: Both emit 'play' events

    User->>Player: pause()
    Player->>Composition: pause()
    Composition-->>Player: emits 'pause' event
    Player-->>User: emits 'pause' event
    Note over Player,Composition: Both emit 'pause' events

    User->>DisplayObject: resume()
    DisplayObject-->>User: emits 'resume' event
    DisplayObject->>Composition: resume()
    Player-->>User: emits 'resume' event
Loading

Poem

A hop, a skip, a playback cheer,
Now "play" and "pause" are crystal clear!
Events abound, the logs ignite,
With "resume" to set things right.
The rabbit dances, code in bloom—
Playback's state now fills the room!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66acf1f and b62bb64.

📒 Files selected for processing (6)
  • packages/effects-core/src/composition.ts (3 hunks)
  • packages/effects-core/src/events/types.ts (1 hunks)
  • packages/effects-threejs/src/three-display-object.ts (1 hunks)
  • packages/effects/src/player.ts (6 hunks)
  • packages/effects/src/types.ts (1 hunks)
  • web-packages/demo/src/interactive.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
packages/effects-threejs/src/three-display-object.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
packages/effects-core/src/composition.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
web-packages/demo/src/interactive.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
packages/effects/src/types.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
packages/effects/src/player.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
packages/effects-core/src/events/types.ts (1)
Learnt from: wumaolinmaoan
PR: galacean/effects-runtime#691
File: packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts:39-42
Timestamp: 2024-10-18T09:15:08.038Z
Learning: In `packages/effects-core/src/plugins/timeline/playables/color-property-mixer-playable.ts`, when accumulating color components, avoid using `clone()` methods because it can cause additional garbage collection overhead.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (15)
web-packages/demo/src/interactive.ts (2)

13-18: LGTM! Proper usage of new player events.

The event listeners correctly handle the new 'play' event with time payload and the 'resume' event without payload, consistent with the type definitions.


42-47: LGTM! Proper usage of new composition events.

The event listeners correctly handle the new 'play' and 'pause' events on the composition, demonstrating the new event-driven playback state system.

packages/effects-threejs/src/three-display-object.ts (1)

170-170: LGTM! Consistent event emission pattern.

The 'resume' event dispatch follows the same pattern as the existing 'pause' event in the pause() method above, maintaining consistency in the event system.

packages/effects/src/types.ts (2)

173-176: LGTM! Well-structured event type definition.

The 'play' event type with time payload is properly defined with clear documentation, consistent with the existing event patterns.


181-184: LGTM! Consistent event type definition.

The 'resume' event type follows the same pattern as the existing 'pause' event with no payload, maintaining consistency in the event system.

packages/effects-core/src/events/types.ts (1)

29-36: LGTM! Consistent event type definitions.

The 'play' and 'pause' event types are well-defined with clear documentation and consistent payload structures that align with the PlayerEvent definitions.

packages/effects-core/src/composition.ts (3)

495-495: LGTM! Correct event emission for pause.

The 'pause' event emission is properly placed in the pause() method, providing explicit notification when the composition is paused.


520-520: LGTM! Correct event emission for play.

The 'play' event emission with time payload is properly placed in the gotoAndPlay() method after resuming, providing explicit notification when playback starts.


562-562: LGTM! Thoughtful implementation to avoid spurious events.

Using direct assignment this.paused = true instead of calling this.pause() prevents unnecessary 'pause' event emission when temporarily restoring the paused state in setTime(). This is a good implementation detail that avoids confusing event notifications.

packages/effects/src/player.ts (6)

388-391: LGTM! Appropriate event emission for auto-playing compositions.

The logic correctly checks if any loaded compositions are not paused and emits a 'play' event accordingly. This provides clear feedback about the initial playback state after loading scenes.


446-446: LGTM! Explicit play event emission.

The 'play' event is appropriately emitted when the player's play() method is called, providing consistent event notifications for playback state changes.


466-466: LGTM! Consistent event emission with time parameter.

The 'play' event is correctly emitted with the specified time parameter, maintaining consistency with the gotoAndPlay functionality.


484-484: LGTM! Appropriate pause event emission.

The 'pause' event is correctly emitted when gotoAndStop() is called, as this method stops playback at a specific time.


540-540: LGTM! Explicit resume event emission.

The 'resume' event is appropriately emitted when the player resumes from a paused state, providing clear notification of playback resumption.


620-623: LGTM! Improved playing state calculation.

The playing state is now correctly derived from the actual paused state of compositions using this.compositions.some(c => !c.getPaused()), which is more accurate than maintaining internal flags. This ensures the 'update' event always reflects the true playback state.

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

1 participant