Skip to content

[UI/UX] Stop Button Appears Only During Active Playback #5778#5779

Open
anshukaushik4700 wants to merge 4 commits intosugarlabs:masterfrom
anshukaushik4700:fix-stop-button-visibility
Open

[UI/UX] Stop Button Appears Only During Active Playback #5778#5779
anshukaushik4700 wants to merge 4 commits intosugarlabs:masterfrom
anshukaushik4700:fix-stop-button-visibility

Conversation

@anshukaushik4700
Copy link
Contributor

@anshukaushik4700 anshukaushik4700 commented Feb 18, 2026

Description:

This PR fixes issue #5778
where the "Stop" button was visible on the Music Blocks home page even when no music was playing. Previously, both "Play" and "Stop" buttons were visible initially, which could be confusing for users.

With this update:

  • The Stop button now only appears when a project is actively playing.
  • Once playback stops or finishes naturally, the Stop button disappears, returning to the initial state.
  • This improves the UI/UX by providing clear feedback to users about playback state.

Steps to Reproduce:

  1. Open the Music Blocks home page.
  2. Observe the "Play" and "Stop" buttons before interacting with any project.
  3. Previously, the "Stop" button was visible even though no music was played.

Expected Behavior After Fix:

  • Initially, only the Play button is visible.
  • When a pattern is played, the Stop button appears, allowing users to stop playback.
  • After stopping, the Stop button disappears automatically.

Screenshots / Video

image

Implementation Details:

  • Updated the UI logic controlling button visibility during playback.

  • Ensured no impact on existing functionalities.

  • Code changes are minimal and fully backward-compatible.

  • Bug Fix

  • Feature

  • Performance

  • Tests

  • Documentation

closes #5778

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@vanshika2720
Copy link
Contributor

@anshukaushik4700 This change toggles visibility based only on button clicks, not actual playback state.
That can desync the UI when playback ends naturally or is triggered programmatically. The visibility should be tied to the real playback lifecycle instead.

@anshukaushik4700
Copy link
Contributor Author

@vanshika2720 Thanks for the feedback — that’s a good point.

The original intent of this change was to address the initial UX issue on the home page by ensuring the Stop button is hidden before any playback begins and only shown once playback starts via user interaction.

I agree that tying the visibility purely to click events can desync the UI if playback ends naturally or is triggered programmatically. To make this more robust, I can update the implementation to hook into the existing playback start/stop lifecycle so the Stop button reflects the actual playing state rather than just button clicks.

I’ll push an update aligning the visibility with the real playback state.

@anshukaushik4700
Copy link
Contributor Author

Hello @walterbender @omsuneri, I’d appreciate it if you could review this PR at your convenience. Thank you!

@walterbender
Copy link
Member

I haven't tested this yet, but there are lots of corner cases you need to consider. Many interactive projects use the start button to load event handlers. The events (e.g., clicking on a mouse) may trigger play, which would require the stop button to become visible.

@anshukaushik4700
Copy link
Contributor Author

Apologies for the delayed response @walterbender sir — I was occupied with academic exams over the past few days.

Thank you for pointing this out. You’re absolutely right — I hadn’t fully considered scenarios where the Start button initializes event handlers and playback is triggered later through user interactions (such as mouse clicks or other events). At the moment, the Stop button visibility is mainly controlled based on direct button clicks, which is not a reliable approach for these interactive cases. I understand, playback may begin independently of the initial Start click, and the Stop button should reflect the actual playback state. I will revise the implementation to tie the Stop button visibility to the real playback state instead of button events and also add corner cases, and I will test it carefully to ensure those corner cases are handled properly.

If there are any specific corner cases you recommend testing against, please let me know — I’d be happy to include them

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

turtle-singer.test.js

@github-actions github-actions bot added the bug fix Fixes a bug or incorrect behavior label Mar 5, 2026
@anshukaushik4700 anshukaushik4700 force-pushed the fix-stop-button-visibility branch from e44d8a4 to 5f27ad3 Compare March 5, 2026 14:27
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

turtle-singer.test.js

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

✅ All Jest tests passed! This PR is ready to merge.

@anshukaushik4700
Copy link
Contributor Author

Hi @walterbender, Please review this solution and let me know if any adjustments are needed!
I've successfully fixed the stop button visibility issue. The button now properly shows/hides based on actual playback state, handling all trigger scenarios.

Changes Made

index.html

  • Removed hardcoded stop button solution
  • Button now managed dynamically by application state

js/activity.js

  • init(): Hide button on startup
  • _doFastButton(): Show button when play is initiated
  • doStopTurtles(): Hide button when stop is triggered

js/turtle-singer.js

  • processNote(): Show button when audio playback starts
  • killAllVoices(): Hide button when all audio stops
  • Added null checks for safe DOM access (prevents Jest errors)

Testing Status ✅

Jest Tests: 106/106 passing ✅

  • All existing tests still pass
  • Fixed killAllVoices lifecycle safety tests
  • Added proper null checks for DOM element access

Manual Testing Completed:

  • ✅ Button hidden on app startup
  • ✅ Button shows when play button clicked
  • ✅ Button hides when stop button clicked
  • ✅ Button shows with keyboard shortcuts (Space/Enter)
  • ✅ Button shows with event handler triggers
  • ✅ Button hides when audio playback stops

@walterbender
Copy link
Member

I am pretty confused by the behavior at this point. It is nice to not have the stop button before anything is running. But the appearance and state of the start button seems inconsistent thereafter. Just with the default project, run from start and the stop button stays red after play ends. Clicking on the start block, it never turns red.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Fixes a bug or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI/UX] Stop Button Appears Even When Nothing Is Playing

3 participants