Skip to content

thewhodidthis/playah

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

about

Helps control video elements with autoplay available down to iOS 8.

setup

Download from the npm registry:

# Add to package.json
npm install playah

usage

Feed with a <video> element as for example,

import createPlayer from "playah"

const video = document.createElement("video")

"playsinline loop autoplay".split(" ").forEach((v) => {
  video.setAttribute(v, "")
})

video.setAttribute("src", "BigBuckBunny.mp4")

// Instantiating past video setup is
// kind of important in this example
const { play, stop } = createPlayer(video)

let paused = 1

video.addEventListener("loadstart", () => {
  paused = 0
})

video.addEventListener("click", (e) => {
  e.preventDefault()

  paused = paused ? play() : stop()
}, false)

document.body.appendChild(video)