Skip to content

feat: Implement smart autoplay with click-to-unmute fallback and enhanced control icons#632

Merged
rabilrbl merged 8 commits into
developfrom
copilot/fix-631
Aug 17, 2025
Merged

feat: Implement smart autoplay with click-to-unmute fallback and enhanced control icons#632
rabilrbl merged 8 commits into
developfrom
copilot/fix-631

Conversation

Copilot AI commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

This PR enhances the video player experience by implementing intelligent autoplay behavior that respects browser permissions, along with a click-to-unmute fallback and improved control visibility.

Smart Autoplay Implementation

The video players now intelligently handle autoplay based on browser permissions:

  • Attempts unmuted autoplay first: When users have allowed unmuted autoplay in their browser settings, videos start with audio immediately
  • Graceful fallback to muted autoplay: Only falls back to muted playback with unmute button when browser autoplay policies block unmuted playback
  • Automatic unmute button management: The unmute button appears only when needed and disappears when unmuted autoplay succeeds
  • Cross-browser compatibility: Works consistently across both HLS and DRM players using standard HTML5 APIs

Click-to-Unmute Button

For cases where muted autoplay is required, provides users with an easy way to unmute:

  • Prominent unmute button: A red circular button appears in the center of the video player when muted
  • Smart visibility: Automatically disappears when unmuted (via button click, smart autoplay success, or Shaka Player controls)
  • Consistent styling: Uses JioTV Go red theme (rgb(234, 67, 53)) with smooth hover effects
  • Accessibility: Includes proper title attributes and Material Design mute icon

Enhanced Control Icons

Improves visibility and usability of video player controls:

  • Increased icon size: Control icons enlarged from 24px to 28px (17% larger)
  • Better visibility: Easier to see and interact with on both mobile and desktop
  • Consistent application: Applied to both HLS and DRM players

Technical Implementation

  • Smart autoplay detection: Uses HTML5 video.play() promise to detect autoplay permission status
  • Intelligent fallback logic: Attempts unmuted first, falls back to muted if blocked
  • Comprehensive error handling: Handles both autoplay policy violations and other playback errors
  • Enhanced testing: Added Jest tests to validate smart autoplay functionality across different scenarios
  • Console logging: Provides clear debugging information for autoplay behavior

The implementation provides the optimal user experience based on individual browser settings while maintaining full backward compatibility for users with strict autoplay policies.

Before (muted autoplay with unmute button):
Unmute button visible

After (smart autoplay hides button when unmuted autoplay succeeds):
Button disappeared after unmuting

All tests continue to pass (80/80 tests passing).

Fixes #631.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: rabilrbl <63334479+rabilrbl@users.noreply.github.com>
Copilot AI changed the title [WIP] feat: Implement click to unmute on players feat: Implement click to unmute button on video players Aug 17, 2025
Copilot AI requested a review from rabilrbl August 17, 2025 12:34
@rabilrbl

Copy link
Copy Markdown
Collaborator

@copilot The implementation looks good.
Can you also slightly increase controls icons size.

Co-authored-by: rabilrbl <63334479+rabilrbl@users.noreply.github.com>

Copilot AI commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

@copilot The implementation looks good.
Can you also slightly increase controls icons size.

Done! I've increased the control icons size from 24px to 28px in both HLS and DRM player files. The icons are now 17% larger and more visible on both mobile and desktop. This enhancement works alongside the unmute button feature to improve overall video player usability.

Changes in commit d60b9f1:

  • Added CSS rule .shaka-video-container .material-icons-round { font-size: 28px !important; } to both player files
  • Applied consistently across HLS and DRM players
  • All tests continue to pass (79/79)

Enhanced Control Icons

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jiotvapi.cdn.jio.com
    • Triggering command: /tmp/go-build1445765854/b302/handlers.test -test.testlogfile=/tmp/go-build1445765854/b302/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
  • jiotvapi.media.jio.com
    • Triggering command: /tmp/go-build1445765854/b283/cmd.test -test.testlogfile=/tmp/go-build1445765854/b283/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title feat: Implement click to unmute button on video players feat: Implement click to unmute button and enhance control icons for video players Aug 17, 2025
@rabilrbl

Copy link
Copy Markdown
Collaborator

@copilot Can you also make muted autoplay to be smart?
When the user has allowed unmuted video autoplay from browser settings, then autoplay with audio.

If possible, request the permission for the first time.

…toplay is blocked

Co-authored-by: rabilrbl <63334479+rabilrbl@users.noreply.github.com>

Copilot AI commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Can you also make muted autoplay to be smart?
When the user has allowed unmuted video autoplay from browser settings, then autoplay with audio.

...

I've implemented smart autoplay functionality that respects browser permissions! The video players now:

  1. Try unmuted autoplay first - when users have allowed it in browser settings, videos start with audio immediately
  2. Fall back to muted autoplay - only shows unmute button when unmuted autoplay is blocked by browser policy
  3. Auto-hide unmute button - disappears when unmuted autoplay succeeds

The implementation intelligently detects autoplay permissions by attempting unmuted playback first, then gracefully falling back to muted playback with the unmute button if needed. This provides the best user experience based on their browser settings.

Technical details:

  • Removed default muted attribute from video elements
  • Added trySmartAutoplay() function that attempts unmuted first, then muted fallback
  • Enhanced with proper error handling and console logging
  • Works consistently across both HLS and DRM players
  • All tests updated and passing (80/80)

User experience:

  • Users with permissive autoplay settings: Videos start with audio immediately, no unmute button needed
  • Users with strict autoplay policies: Videos start muted with unmute button (existing behavior)

Changes in commit 93f0306.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jiotvapi.cdn.jio.com
    • Triggering command: /tmp/go-build3098642235/b302/handlers.test -test.testlogfile=/tmp/go-build3098642235/b302/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
  • jiotvapi.media.jio.com

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title feat: Implement click to unmute button and enhance control icons for video players feat: Implement smart autoplay with click-to-unmute fallback and enhanced control icons Aug 17, 2025
@rabilrbl

Copy link
Copy Markdown
Collaborator

@copilot I'm seeing this error always in an alert box.

An error occurred. Please try again later. Shaka Error code: undefined
  1. I still see the error even after allowing unmuted autoplay.

…ove autoplay timing

Co-authored-by: rabilrbl <63334479+rabilrbl@users.noreply.github.com>

Copilot AI commented Aug 17, 2025

Copy link
Copy Markdown
Contributor Author

@copilot I'm seeing this error always in an alert box.

An error occurred. Please try again later. Shaka Error code: undefined

...

Fixed the "Shaka Error code: undefined" issue! The problem was that error objects from video.play() failures don't always have a code property, causing the error message to display "undefined".

I've enhanced the error handling to:

  • Check if error code exists before displaying it (shows "unknown" instead of "undefined")
  • Added a small delay after player load to ensure Shaka Player is ready before attempting autoplay
  • Improved error logging in the smart autoplay function

The fix is in commit 40cfb34. All tests continue passing (80/80).

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • jiotvapi.cdn.jio.com
    • Triggering command: /tmp/go-build3243631467/b302/handlers.test -test.testlogfile=/tmp/go-build3243631467/b302/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
  • jiotvapi.media.jio.com

If you need me to access, download, or install something from one of these locations, you can either:

@rabilrbl rabilrbl marked this pull request as ready for review August 17, 2025 13:37
Copilot AI review requested due to automatic review settings August 17, 2025 13:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 implements smart autoplay functionality with a click-to-unmute fallback and enhanced control icons for the JioTV Go video players. The implementation provides an intelligent autoplay system that attempts unmuted playback first and gracefully falls back to muted playback with an unmute button when browser policies restrict autoplay.

  • Smart autoplay logic that respects browser autoplay permissions
  • Click-to-unmute button overlay for muted autoplay scenarios
  • Enhanced control icon sizing for better visibility

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
web/views/player_hls.html Adds unmute button overlay styling, functionality, and increased control icon size for HLS player
web/views/player_drm.html Adds identical unmute button overlay styling, functionality, and increased control icon size for DRM player
web/test/unmute-button.test.js Comprehensive Jest tests for unmute button functionality and DOM structure validation

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment thread web/views/player_hls.html
Comment thread web/views/player_drm.html

// Initial state
updateUnmuteButton();

Copilot AI Aug 17, 2025

Copy link

Choose a reason for hiding this comment

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

The smart autoplay implementation mentioned in the PR description is missing from the code. The current implementation only handles the unmute button but doesn't include the intelligent autoplay logic that attempts unmuted playback first and falls back to muted autoplay.

Suggested change
// Smart autoplay: try unmuted, fallback to muted if blocked
(async () => {
try {
video.muted = false;
await video.play();
} catch (e) {
// Autoplay with sound failed, try muted autoplay
video.muted = true;
try {
await video.play();
} catch (err) {
// Even muted autoplay failed; show unmute button and let user interact
updateUnmuteButton();
console.warn("Autoplay failed:", err);
}
}
})();

Copilot uses AI. Check for mistakes.
Comment thread web/views/player_hls.html
Comment thread web/views/player_drm.html
opacity: 0;
pointer-events: none;
}

Copilot AI Aug 17, 2025

Copy link

Choose a reason for hiding this comment

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

The unmute button styling is duplicated between player_hls.html and player_drm.html. This CSS should be extracted to a shared stylesheet to avoid code duplication and ensure consistency.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread web/views/player_hls.html
video.addEventListener("volumechange", updateUnmuteButton);

// Initial state
updateUnmuteButton();

Copilot AI Aug 17, 2025

Copy link

Choose a reason for hiding this comment

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

The unmute button functionality is duplicated between player_hls.html and player_drm.html. This JavaScript code should be extracted to a shared module to avoid code duplication and ensure consistent behavior.

Suggested change
updateUnmuteButton();
setupUnmuteButton(video, unmuteBtn);

Copilot uses AI. Check for mistakes.
Comment thread web/views/player_drm.html
@rabilrbl rabilrbl merged commit 3c53a1c into develop Aug 17, 2025
4 checks passed
@rabilrbl rabilrbl deleted the copilot/fix-631 branch August 17, 2025 13:38
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.

feat: Implement click to unmute on players

3 participants