Skip to content
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

Mute videos on iOS devices when tapped #159

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielraffel
Copy link

@danielraffel danielraffel commented Oct 18, 2023

EDIT(paulirish): daniel left this amazing comment on an ios branch commit.. here's that comment:

If/when you might be ready to pick this back up I have a hunch the issue on iOS / iPad is related to audio volume:

Webkit Policy:
https://webkit.org/blog/6784/new-video-policies-for-ios/#:~:text=elements%20will%20be%20allowed,user%20gesture%2C%20playback%20will%20pause.

Apple dev policy
https://developer.apple.com/documentation/webkit/delivering_video_content_for_safari/

"By default, autoplay executes only if the video doesn’t contain an audio track, or if the video element includes the muted attribute. Video playback pauses if the element gains an audio track, becomes unmuted without user interaction, or if the video is no longer onscreen (either by CSS or due to the user scrolling the page)."

How to repro:

  1. if you mute the yt player, then refresh the page and tap a lite-youtube embedded video, it seems to always play.
  2. however, if you unmute the yt player, then refresh the page and tap a lite-youtube embedded video, it seems to require double click to play at least the first time and may/may not play on subsequent embeds elsewhere on the page.

So, it appears this might be bumping up against policy around audio volume (being set to on) when a video starts playing which isn't muted; making this harder than it should be. Hope that's helpful!

proposed a fix: #159
This mutes videos when they are played on an iPad or iPhone. Specifically, it adds the parameter 'mute', '1' to the video URL if the platform is identified as iPad or iPhone. This is achieved using the test /iPad|iPhone|iPod/.test(navigator.platform). The purpose is to mute videos automatically on these devices upon tapping.


The change introduces a condition to mute videos when they are played on an iPad or iPhone. Specifically, it adds the parameter 'mute', '1' to the video URL if the platform is identified as iPad or iPhone. This is achieved using the test /iPad|iPhone|iPod/.test(navigator.platform).

The purpose is to mute videos automatically on these devices upon tapping based on the findings I mentioned here: 9dfd33a#commitcomment-130244618

@paulirish
Copy link
Owner

navigator.platform no longer has anything useful. and .. there's no longer anything in navigator that communicates its an ipad.

i think best we can do is userAgent.includes('Intel Mac OS X') ... this'll catch desktop safari too.. but.. Apple seems fairly intent on making those two indistinguishable. So.. oh well.

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.

2 participants