How to autoplay HTML5 videos with sound (unmuted) in Safari - javascript

Safari and Chrome is not allowing video to autoplay if sound is on by default (unmuted). If you mute the video, it will autoplay, and the user is forced to enable sound. Fine and well, I can live with this.
However, in researching this, I found that YouTube (Safari 11, MacOS High Sierra), is allowing subsequent videos to be played with sound ON if the user turns sound on for a given video. Likewise, if user mutes the video, clicks onto a different video, this video will autoplay muted until user toggles the sound on. I would love to replicate this on a site in which I have created a video gallery of sorts. Each video does live on it's own page, and navigating the gallery will take user to a new page in the browser. This needs to stay the same, for multiple reasons (as opposed to creating a single media element and dynamically changing video source).
Alternatively, is there a way to convince Safari that a user has intentionally clicked a button in order to watch a video, thus allowing autoplay with sound on, when the user is simply clicking a link (in the form of a "Play Video Now" button) to a page with the video embedded?

Related

How does YouTube start a video unmuted skipping JavaScript restriction about unmuted videos?

I noticed that if you open a YouTube link, the video will start autoplaying with sound, even if I haven't interacted with the page.
For what I know, the browser needs the user to interact with the page to allow unmuted videos.
How does YouTube that? How can I implement it to my webpage?

How to "autoplay" video unmuted on mobile using JWPlayer

I am using JWPlayer for my videos on my site. What I want to achieve is to autostart videos unmuted. I have autostart feature on but the videos start muted.
The thing is I have playlists which directly refreshes the page instead of changing the video (i have to work this way). Whenever the page changes, the video starts automatically but muted just as before.
Is there any trick that I can autoplay videos unmuted on mobile browsers?
Thank you in advance!
The limitation is related to HTML5 videos, not just the JWPlayer - for various reasons video autoplay on mobile devices has historically been limited or restricted.
This was typically to avoid excessive bandwidth charges for users and also to avoid annoying users by having a video or audio suddenly play unexpectedly for them.
The restrictions are different for different platforms but it is fair to say that most platforms have eased the restrictions in recent years and autoplay of muted video is often supported now. Autoplay of united videos on mobile devices is still generally not allowed.
You can see the summary of Webkits policies for iOS as an example here: https://webkit.org/blog/6784/new-video-policies-for-ios/
There is a specific focus on the audio track - e.g.:
video elements will be allowed to autoplay without a user gesture if their source media contains no audio tracks.
video muted elements will also be allowed to autoplay without a user gesture.
If a video element gains an audio track or becomes un-muted without a user gesture, playback will pause.

How mobile YouTube page autoplay videos on iOS?

I'm trying to get it understand but after 2 days of digging the code I thought that I will post my issue here...
According to Apple's documentation, autoplaying videos on iOS devices cannot be done without user interaction first (e.g. tap on video). Despite that, mobile YouTube (m.youtube.com) is able to autoplay its videos just after loading a page with video.
Does anyone know how they are doing it?
PS. I've checked all available JS/HTML techniques of autoplaying videos on website on iOS (e.g. iframe, fake click, triggering touch event on video, fetching video with XHR).
I believe that youtube.com is a single page app. So when the user clicks on the video from the list view the page is not loading and their javascript uses that initial click, that leads to the video page, as the click that starts the video. It's not actually autoplaying, it's just a trick.

How can I simulate a touch in a UIWebView?

I want to automatically play a YouTube video but because of how YouTube's view counter is set up, autoplay views will not count as views.
How can I simulate a user interaction tap in a UIWebView so YouTube thinks that the user pressed/tapped play?
Or do you "think" that a very near version of iOS will support this?
Trying to phrase that in NDA accordance. Do you think it would work if I changed the user agent of the UIWebView to a desktop user agent and displayed a standard YouTube page?
On the desktop YouTube videos autoplay on Youtube.com but this does not work on mobile.
I have set mediaPlaybackRequiresUserAction to no.

Greasemonkey script to pause video playback on non-active tabs

Often when browsing in Firefox, I'll right click on a link, and open it in a separate tab to view later, and go on reading the current page. When the link is a Youtube script, however, playback starts immediately even though the tab isn't active. Other video players (like fora.tv and TED.com) don't start playback until you activate that tab.
Is there a greasemonkey script that I can use to make sure that videos (and especially Youtube videos) are paused unless their tab is active?
I found two options:
"Youtube Alternate Video Player" (greasemonkey script)
http://userscripts.org/scripts/show/13955
Script Summary:
Replaces the youtube flash video player with FlowPlayer flash video player.
replaces the youtube player
no hd
no 16:9
Firefox Add-On "TubeStop"
http://www.chrisfinke.com/addons/tubestop/
disables the autoplay on YouTube videos
does it every time (even if the tab is active)
I will keep the TubeStop addon for now.
I think Youtube now does this by default (only playing a video when the tab the video is in is activated)

Categories

Resources