0.1.1 • Published 9 months ago

videojs-rotate-fullscreen v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Full-screen mode control when changing the mobile device orientation

  1. Support window mode
  2. Pause control
  3. Auto enter/exit fullscreen

Example

/* Default values */
player.rotateFullScreen({
  onlyInView: true, // - Rotate only when the video fits in the viewport
  enterOnRotate: true, // - Enter fullscreen mode on rotate.
  exitOnRotate: true, // - Exit fullscreen mode on rotate.
  alwaysInLandscapeMode: true, // - Always in landscape mode.
  rotateWithPause: false, // - Enter fullscreen even when paused.
  windowMode: false, // - Use window mode instead of fullscreen. (option for Safari with custom ui)
  disabled: false, // - Manual disable rotation
})

React Example

import { useEffect, useRef } from 'react'
import videojs from 'video.js'
import 'video.js/dist/video-js.css'
import 'videojs-rotate-fullscreen'

export const Video = (props) => {
  const videoRef = useRef(null)
  const playerRef = useRef(null)

  const { fill, playsinline, playbackRates, src, type } = props

  const videoJsOptions = {
    fill: fill,
    responsive: false,
    fluid: false,
    playbackRates: playbackRates,
    sources: [
      {
        src: src,
        type: type ?? 'video/mp4',
      },
    ],
  }

  useEffect(() => {
    if (!playerRef.current) {
      const videoElement = document.createElement('video-js')
      videoRef.current.appendChild(videoElement)
      const player = (playerRef.current = videojs(videoElement, videoJsOptions))

      player.rotateFullScreen({
        enterOnRotate: true,
        exitOnRotate: true,
        alwaysInLandscapeMode: false,
        rotateWithPause: true,
        windowMode: false,
        onlyInView: true,
      })
    } else {
      const player = playerRef.current
      player.src(videoJsOptions.sources)
    }

    return () => {
      const player = playerRef.current
      if (player && !player.isDisposed()) {
        player.dispose()
        playerRef.current = null
      }
    }
  }, [videoJsOptions])

  return (
    <div
      data-vjs-player
      ref={videoRef}
      style={{
        width: '100%',
        height: '100%',
      }}
    />
  )
}
0.1.1

9 months ago

0.1.0

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago