Video-player for React that is identical to YouTube's in-app player. YouTube video-player clone.

  • By Viktor
  • Last update: Oct 18, 2022
  • Comments: 6

Replica Player

Minzipped size License

Video-player for React that is identical to YouTube's in-app player. YouTube video-player clone.

[Todo: add comparison of original player and Replica Player]

Work in progress

Motivation

YouTube player is probably the best universal video-player ever created, I have never met a player in the web with such a good UX. However, YouTube made it's impossible to play custom videos in YouTube native player. There was some attempts to recreate this player, but in most they're just examples and prototypes. There was no full-features, mobile-first, production-ready YouTube's player clone.

Features

  • Works on native HTML5 video element, so any format, that your browser can play, can also be played in Replica Player
  • On mobile it's identical to YouTube's in-app player, on PC it's identical to YouTube's web player
  • Features supported (roadmap):
    • Fast-forwarding
    • Speed change
    • Quality versions
    • Subtitles
    • Hotkeys
    • Episodes
    • Playlists
    • Aspect-ratio view modes: fit, cover, resize (mobile only)
    • Localization
    • Chrome cast (using Presentation API)
  • React v18 supported. Vue, Angular and Vanilla JS support may be added in future.
  • TypeScript supported
  • MIT licensed, not patented by Google LLC

Install

npm i replica-player
yarn add replica-player

Compiled with TypeScript, bundled with Rollup. Building is done for CJS. If you need ESM code, you can follow instructions in CONTRIBUTING.md file.

Tested with

Use with React

Developed with React 18.2.0

You must import replica-player/dist/index.css along with the component itself. For SSR and Next.js, import css globally in pages/_app.js file.

import React from 'react'
import ReplicaPlayer from 'replica-player'
import 'replica-player/dist/index.css'

export default function YourApp() {
  // Component can hold a ref
  const ref = React.useRef()

  return (
    <ReplicaPlayer 
      src={'https://www.w3schools.com/html/mov_bbb.mp4'}
      ref={ref}
    />
  )
}

API Reference

Props

Props with types ending with ? are optional.

Prop Type Default Description
src string undefined Media source
width number? 640 Width of player's container. Can be overriden with css styles
height number? 360 Height of player's container. Can be overriden with css styles
resizeMode string? 'fit' One of 'fit', 'cover' and 'fill'
segments Segment?[] [] Array of video segments
componentsProps object? undefined Rest props for any components inside player
componentsProps.container object? undefined Props for player's container div
componentsProps.controls object? undefined Props for player's controls

Interfaces

Segment

Video segment

Prop Type Default Description
timeStart number undefined Seconds from start of the video when segment starts
title string "" Title of segment

Ref API reference

[Todo]

Legal notice

YouTube player's code is minified and copyrighted to YouTube, but the player itself is not patented/copyrighted. You can patent a technology feature (such as splitting videos in chunks, optimisation, which this player doesn't do), brand's logos, but you can't patent/copyright the web component, it's impossible :) Otherwise, everything in the web would be much more complicated.

Source code of this player is written by me, Viktor Shcheclochkov @hloth <[email protected]>, as seen from commits history, and, as stated in LICENSE.md and below, I give anyone with copy of this component a permission to use it in any context as you wish: you can embed ads in it and sell products using this component without need to credit me (but I would appreciate you credit me tho).

License

MIT License

Copyright (c) 2022 Viktor Shchelochkov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Funding

Donate: hloth.dev/donate

Github

https://github.com/VityaSchel/replica-player

Comments(6)

  • 1

    Impossible issue with context menu

    An impossible issue with fucking webkit

    1. Context menu should appear on RMB
    2. Context menu should disappear on blur (LMB outside AND outside of browser window, any else what causes "blur" event)
    3. Native context menu should appear on RMB ONLY IF CONTEXT MENU VISIBLE

    Problem

    Because of React, onContextMenu called AFTER blur event. In blur event ContextMenu disappears, and in onContextMenu handler sees visible=false

    Any variations of timeout not only unreliable but also doesn't work.

  • 2

    Animated buttons are flickering

    Problem

    Because of nature of keyframes animations, when updating path, svg icons are flickering. Also may be an issue with the keyframes themself.

    Possible solution

    1. Check if it's an issue with incorrect keyframes path positions
    2. If not, replace keyframes animations with lottie animations or any other javascript path updater.
  • 3

    Support for native events on video, dispatch to redux when event happens on video ref, not on specific action

    Describe the bug Imagine some user has a binding that muted/unmutes video in web browser. Currently redux state is updated when user presses mute/unmute button. On click event, components changes property in player and dispatches to redux. This way, redux will never change its state if user muted video not using this button.

    Expected behavior It's better to dispatch thunks to redux from native video events (such as onVolumeChange) so every change (including component's changes to player instance) will be recorded and rendered.

  • 4

    Circle status indicator

    On PC, circle status indicator is a transculent centered black circle with different icons depending on different user actions.

    • [x] Play
    • [x] Pause
    • [ ] Volume increase
    • [ ] Volume decrease
    • [ ] Volume mute
    • [ ] Speed increase
    • [ ] Speed decrease
  • 5

    Gestures

    • [ ] PC
      • [x] Single click on player (play/pause)
      • [ ] Double click on player (toggle fullscreen)
    • [ ] Mobile
      • [ ] Single tap on player (show/hide controls)
      • [ ] Double tab on left side of player (fast-forward to -10 seconds)
      • [ ] Double tap on right side of player (fast-forward to +10 seconds)
  • 6

    Hotkeys

    Implement hotkeys for PC version.

    • [ ] Left arrow (fast-forward to -10 seconds)
    • [ ] Right arrow (fast-forward to +10 seconds)
    • [ ] Space (play/pause)
    • [ ] Digits 0-9 (seek)
    • [ ] , (previous keyframe)
    • [ ] . (next keyframe)
    • [ ] Up arrow (increase volume)
    • [ ] Down arrow (decrease volume)
    • [ ] c (toggle subtitles)
    • [ ] f (toggle fullscreen)
    • [ ] m (mute/unmute)
    • [ ] shift+p (previous video in playlist)
    • [ ] shift+n (next video in playlist)
    • [ ] option/alt+left arrow (previous episode)
    • [ ] option/alt+right arrow (next episode)