Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do some websites play video inline in iOS Safari?

Pretty incredible since I thought all videos expanded to play fullscreen in regular safari. Check this out for example:

https://entertainment.theonion.com/the-onion-reviews-rogue-one-1819596116

That video plays inline and doesn't even stop when I switch Safari tabs. What's happening there? Are they using js and HTML5 canvas to render the video or something? How do they sync the sound so well?

like image 352
Gregory Magarshak Avatar asked Jan 06 '17 18:01

Gregory Magarshak


People also ask

How do I get Safari to autoplay videos?

Hold the pointer to the right of Auto-Play, then click the pop-up menu and choose an option: Allow All Auto-Play: Lets videos on this website play automatically. Stop Media with Sound: Blocks autoplay for videos that contain audio, but allows other videos to play.

Why can't I watch videos on websites on iPhone?

When videos not playing on iPhone Safari, you should delete the Safari history, cookies, and caches. Just open iPhone Settings, then select the Safari, and tap the Clear History and Website Data. Also, you can force quit Safari and open it again.


1 Answers

Just constructing an answer based on the link @offbeatmammal posted in his comment.

Also based on new video policies for ios specifically that:

On iPhone, elements will now be allowed to play inline, and will not automatically enter fullscreen mode when playback begins. elements without playsinline attributes will continue to require fullscreen mode for playback on iPhone. When exiting fullscreen with a pinch gesture, elements without playsinline will continue to play inline.

A note about the playsinline attribute:

this attribute has recently been added to the HTML specification, and WebKit has adopted this new attribute by unprefixing its legacy webkit-playsinline attribute. This legacy attribute has been supported since iPhoneOS 4.0, and accordance with our updated unprefixing policy, we’re pleased to have been able to unprefix webkit-playsinline. Unfortunately, this change did not make the cut-off for iOS 10 Developer Seed 2. If you would like to experiment with this new policy with iOS Developer Seed 2, the prefixed attribute will work, but we would encourage you to transition to the unprefixed attribute when support for it is available in a future seed.

Lastly an example:

<video autoplay loop muted playsinline>
  <source src="image.mp4">
  <source src="image.webm" onerror="fallback(parentNode)">
  <img src="image.gif">
</video>

with a fall back that displays an image on video error

function fallback(video)
{
  var img = video.querySelector('img');
  if (img)
    video.parentNode.replaceChild(img, video);
}
like image 63
Alan DeLonga Avatar answered Oct 23 '22 01:10

Alan DeLonga