Convert Figma logo to code with AI

fregante logoiphone-inline-video

📱 Make videos playable inline on the iPhone (prevents automatic fullscreen)

2,056
298
2,056
9

Top Related Projects

🗻 Polyfill object-fit/object-position on <img>: IE9, IE10, IE11, Edge, Safari, ...

37,959

Video.js - open source HTML5 video player

26,497

A simple HTML5, YouTube and Vimeo player

HTML5 <audio> or <video> player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

7,101

:clapper: An extensible media player for the web.

JW Player is the world's most popular embeddable media player.

Quick Overview

iphone-inline-video is a JavaScript library that enables inline video playback on iPhones and iPads. It allows developers to play videos inline within web pages on iOS devices, overcoming the default full-screen-only playback limitation. This library enhances the user experience by providing seamless video integration into web applications.

Pros

  • Enables inline video playback on iOS devices
  • Improves user experience by avoiding full-screen-only playback
  • Lightweight and easy to integrate into existing web projects
  • Supports both programmatic and declarative usage

Cons

  • May have performance implications on older iOS devices
  • Requires JavaScript to be enabled in the browser
  • Limited to iOS devices; not necessary for other platforms
  • May need periodic updates to keep up with iOS changes

Code Examples

  1. Basic usage:
import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video);
  1. Enabling autoplay:
import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video, true);
video.play();
  1. Using with jQuery:
import makeVideoPlayableInline from 'iphone-inline-video';

$('video').each((i, video) => makeVideoPlayableInline(video));

Getting Started

  1. Install the library using npm:
npm install iphone-inline-video
  1. Import and use in your JavaScript file:
import makeVideoPlayableInline from 'iphone-inline-video';

document.addEventListener('DOMContentLoaded', () => {
  const videos = document.querySelectorAll('video');
  videos.forEach(video => makeVideoPlayableInline(video));
});
  1. Ensure your HTML video element has the playsinline attribute:
<video src="video.mp4" playsinline></video>

Competitor Comparisons

🗻 Polyfill object-fit/object-position on <img>: IE9, IE10, IE11, Edge, Safari, ...

Pros of object-fit-images

  • Focuses on image sizing and fitting, addressing a specific CSS property
  • Lightweight solution for cross-browser compatibility of object-fit
  • Simpler implementation for image-related tasks

Cons of object-fit-images

  • Limited to image handling, not addressing video playback issues
  • May require additional solutions for video-related challenges
  • Less versatile for multimedia content manipulation

Code Comparison

object-fit-images:

objectFitImages('img.object-fit');
objectFitImages();
objectFitImages('img.object-fit', {watchMQ: true});

iphone-inline-video:

enableInlineVideo(videoElement);
enableInlineVideo(videoElement, {
    everywhere: true,
    iPad: true
});

Summary

object-fit-images is a specialized tool for handling image fitting across browsers, while iphone-inline-video focuses on enabling inline video playback on iOS devices. The former is more suitable for projects dealing primarily with image layout issues, while the latter addresses specific video playback challenges on mobile platforms. object-fit-images offers a simpler API for image-related tasks, but iphone-inline-video provides more comprehensive solutions for video content on iOS devices.

37,959

Video.js - open source HTML5 video player

Pros of video.js

  • More comprehensive and feature-rich video player solution
  • Supports a wide range of video formats and platforms
  • Extensive plugin ecosystem and customization options

Cons of video.js

  • Larger file size and potentially heavier performance impact
  • Steeper learning curve due to more complex API and configuration options
  • May be overkill for simple inline video playback on iOS devices

Code Comparison

iphone-inline-video:

import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video);

video.js:

import videojs from 'video.js';

const player = videojs('my-video', {
  controls: true,
  sources: [{ src: 'path/to/video.mp4', type: 'video/mp4' }]
});

Summary

iphone-inline-video is a lightweight solution specifically designed for enabling inline video playback on iOS devices. It's simple to use and has a small footprint, making it ideal for projects that only need to address this specific issue.

video.js, on the other hand, is a full-featured video player library that offers cross-platform compatibility, extensive customization options, and support for various video formats. While it provides a more comprehensive solution, it may be excessive for projects that only require inline video playback on iOS.

Choose iphone-inline-video for a focused, lightweight solution to iOS inline video playback, or opt for video.js when you need a versatile, feature-rich video player across multiple platforms.

26,497

A simple HTML5, YouTube and Vimeo player

Pros of Plyr

  • More comprehensive media player solution, supporting HTML5 video, audio, YouTube, and Vimeo
  • Extensive customization options and API for advanced control
  • Active development with regular updates and a larger community

Cons of Plyr

  • Larger file size and potentially more complex setup
  • May include unnecessary features for simple inline video playback
  • Requires more configuration for basic use cases

Code Comparison

Plyr initialization:

const player = new Plyr('#player', {
  controls: ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen'],
  settings: ['captions', 'quality', 'speed', 'loop']
});

iPhone-inline-video usage:

import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video);

Summary

Plyr is a feature-rich media player library offering extensive customization and support for various media types. It's ideal for projects requiring a full-featured player with advanced controls. iPhone-inline-video, on the other hand, is a lightweight solution specifically designed to enable inline video playback on iOS devices. It's more suitable for simple use cases where only inline video functionality is needed, especially on iOS.

HTML5 <audio> or <video> player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.

Pros of MediaElement

  • More comprehensive media player solution with support for various audio and video formats
  • Cross-browser compatibility, including older browsers and mobile devices
  • Extensive plugin system for customization and additional features

Cons of MediaElement

  • Larger file size and potentially more complex setup
  • May be overkill for simple inline video playback on iOS devices
  • Requires more resources and can be slower to load

Code Comparison

MediaElement:

var player = new MediaElementPlayer('player1', {
    features: ['playpause', 'progress', 'current', 'duration', 'volume'],
    success: function(mediaElement, domObject) {
        // Player initialization successful
    }
});

iPhone-inline-video:

import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video);

Summary

MediaElement is a full-featured media player solution with broad compatibility and customization options, while iPhone-inline-video focuses specifically on enabling inline video playback on iOS devices. MediaElement offers more functionality but comes with increased complexity and resource requirements. iPhone-inline-video provides a simpler, lightweight solution for its specific use case. The choice between the two depends on the project's requirements and target platforms.

7,101

:clapper: An extensible media player for the web.

Pros of Clappr

  • More feature-rich and versatile, supporting multiple video sources and plugins
  • Actively maintained with regular updates and a larger community
  • Cross-platform compatibility, including desktop and mobile devices

Cons of Clappr

  • Larger file size and potentially more complex setup
  • May be overkill for simple inline video playback on iOS devices
  • Steeper learning curve for basic implementation

Code Comparison

iphone-inline-video:

import makeVideoPlayableInline from 'iphone-inline-video';

const video = document.querySelector('video');
makeVideoPlayableInline(video);

Clappr:

var player = new Clappr.Player({
  source: "http://your.video/here.mp4",
  parentId: "#player"
});

Summary

iphone-inline-video is a lightweight solution specifically designed for enabling inline video playback on iOS devices. It's simple to implement and has a small footprint, making it ideal for projects with focused requirements.

Clappr, on the other hand, is a more comprehensive video player solution with broader compatibility and extensive features. It's suitable for projects requiring advanced video playback capabilities across multiple platforms, but may be excessive for simpler use cases.

Choose iphone-inline-video for iOS-specific inline video needs, and Clappr for more complex, cross-platform video player requirements.

JW Player is the world's most popular embeddable media player.

Pros of JW Player

  • More comprehensive video player solution with advanced features
  • Supports a wider range of platforms and devices
  • Offers analytics and monetization options

Cons of JW Player

  • Larger file size and more complex implementation
  • Requires a license for commercial use
  • May be overkill for simple inline video playback needs

Code Comparison

iPhone Inline Video:

makeVideoPlayableInline(video, {
  playsinline: true,
  muted: true,
  autoplay: true
});

JW Player:

jwplayer("myElement").setup({
  file: "path/to/video.mp4",
  width: "100%",
  aspectratio: "16:9",
  autostart: true
});

Summary

iPhone Inline Video is a lightweight solution specifically designed for enabling inline video playback on iOS devices. It's simple to implement and focuses on solving a specific problem.

JW Player, on the other hand, is a full-featured video player with support for various platforms, advanced customization options, and additional features like analytics and monetization. It's more suitable for complex video playback requirements and large-scale implementations.

Choose iPhone Inline Video for simple inline video playback on iOS, and JW Player for more comprehensive video player needs across multiple platforms.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

No longer needed :tada:

iOS now supports this natively since v10. So long, and thanks for all the videos!

iphone-inline-video

Make videos playable inline on Safari on iPhone (prevents automatic fullscreen)

gzipped size Travis build status npm version

This enables iOS 10's playsinline attribute on iOS 8 and iOS 9 (almost a polyfill). It lets you:

  • Play videos without going fullscreen on the iPhone (demo)
  • Play silent videos without user interaction
  • Autoplay silent videos with the autoplay attribute (demo)
  • Use videos as WebGL/ThreeJS textures (demo)

Demo

Main features

  • <2KB, standalone (no frameworks required)
  • No setup: include it, call enableInlineVideo(video), done
  • No custom API for playback, you can just call video.play() on click
  • Supports audio
  • Supports autoplay on silent videos
  • Doesn't need canvas
  • Doesn't create new elements/wrappers
  • It works with existing players like jPlayer
  • Disabled automatically on iOS 10+

Limitations:

  • Needs user interaction to play videos with sound (standard iOS limitation)
  • Limited to iPhone with iOS 8 and 9. iPad support needs to be enabled separately. It's disabled on Android.
  • The video framerate depends on requestAnimationFrame, so avoid expensive animations and similar while the video is playing. Try stats.js to visualize your page's framerate
  • Known issues

Install

Pick your favorite:

<script src="dist/iphone-inline-video.min.js"></script>
npm install --save iphone-inline-video
var enableInlineVideo = require('iphone-inline-video');
import enableInlineVideo from 'iphone-inline-video';

Usage

You will need:

  • a <video> element with the attribute playsinline (required on iOS 10 and iOS 11. Why?)

    <video src="file.mp4" playsinline></video>
    
  • the native play buttons will still trigger the fullscreen, so it's best to hide them when iphone-inline-video is enabled. More info on the .IIV CSS class

    .IIV::-webkit-media-controls-play-button,
    .IIV::-webkit-media-controls-start-playback-button {
        opacity: 0;
        pointer-events: none;
        width: 5px;
    }
    
  • the activation call

    // one video
    var video = document.querySelector('video');
    enableInlineVideo(video);
    
    // or if you're already using jQuery:
    var video = $('video').get(0);
    enableInlineVideo(video);
    
    // or if you have multiple videos:
    $('video').each(function () {
    	enableInlineVideo(this);
    });
    

Done! It will only be enabled on iPhones and iPod Touch devices.

Now you can keep using it just like you would on a desktop. Run video.play(), video.pause(), listen to events with video.addEventListener() or $(video).on(), etc...

BUT you still need user interaction to play the audio, so do something like this:

enableInlineVideo(video);
video.addEventListener('touchstart', function () {
	video.play();
});

If at some point you want to open the video in fullscreen, use the standard (but still prefixed) webkitEnterFullScreen() API, but it has some caveats.

Usage with audio-less videos

If your video file doesn't have an audio track, then must set a muted attribute:

<video muted playsinline src="video.mp4"></video>

Usage with autoplaying videos

The autoplay attribute is also supported, if muted is set:

<video autoplay muted playsinline src="video.mp4"></video>

Muted videos can also be played without user interaction — which means that video.play() doesn't need to be called inside an event listener:

<video muted playsinline src="video.mp4"></video>
setTimeout(function () { video.play(); }, 1000); // example

Usage on iPad

The iPad already supports inline videos so IIV is not enabled there.

The only reason to enabled IIV on iPad:

  • you want muted videos to autoplay, or
  • you want to play videos without user interaction

To enabled IIV on the iPad:

enableInlineVideo(video, {
	iPad: true
});

Notes about iOS 10

New features in iOS 10 and iOS 11:

  • videos play inline:

    <video playsinline src="video.mp4"></video>
    
  • muted videos play inline without user interaction:

    <video muted playsinline src="video.mp4"></video>
    
    setTimeout(function () { video.play(); }, 1000); // example
    
  • muted videos autoplay inline:

    <video autoplay muted playsinline src="video.mp4"></video>
    

Essentially everything that this module does, so iphone-inline-video will be automatically disabled on iOS 10-11. Make sure you use the playsinline attribute.

License

MIT © Federico Brigante

NPM DownloadsLast 30 Days