API Docs

Bridge type for working with video playback in JavaScript

HSVideo wraps an AVQueuePlayer and can be embedded in an hs.ui.window via .video(), or driven entirely from JavaScript with play(), pause(), seek(), loop(), and volume.

Loading Video

Each entry may be a local file path (~ is expanded) or a remote URL string. Multiple entries are queued and play back to back, in order.

// A single local file
const clip = HSVideo.fromURLs(["~/Movies/clip.mp4"])

// A playlist mixing a local file and a remote stream
const playlist = HSVideo.fromURLs(["~/Movies/intro.mp4", "https://example.com/video.mp4"])

Playback Control

const clip = HSVideo.fromURLs(["~/Movies/clip.mp4"])
clip.volume = 0.5
clip.loop(true)
clip.play()
// ... later ...
clip.seek(30)
clip.pause()

Looping

Gapless looping (via AVPlayerLooper) is only supported when the playlist contains a single URL. Calling loop(true) on a multi-URL playlist has no effect (the playlist just plays through once) and logs a warning.

Properties

volume

number
The playback volume, from 0.0 (silent) to 1.0 (full volume)

Methods

staticHSVideo.fromURLs(urls) -> HSVideo

Load a playlist of videos to play back to back, in order
HSVideo.fromURLs(urls) -> HSVideo
Name Type Description
urls string[] Each entry is a local file path (`~` is expanded) or a remote URL string
HSVideo
An HSVideo object, or null if the list is empty or an entry couldn't be resolved
const clip = HSVideo.fromURLs(["~/Movies/clip.mp4"])
const playlist = HSVideo.fromURLs(["~/Movies/intro.mp4", "https://example.com/video.mp4"])

play() -> HSVideo

Start (or resume) playback
play() -> HSVideo
HSVideo
Self for chaining
clip.play()

pause() -> HSVideo

Pause playback
pause() -> HSVideo
HSVideo
Self for chaining
clip.pause()

seek(seconds) -> HSVideo

Seek to a specific position
seek(seconds) -> HSVideo
Name Type Description
seconds number The position to seek to, in seconds
HSVideo
Self for chaining
clip.seek(30)

loop(enabled) -> HSVideo

Enable or disable gapless looping Only supported when this HSVideo was created from a single-URL playlist. Enabling loop on a multi-URL playlist has no effect and logs a warning.
loop(enabled) -> HSVideo
Name Type Description
enabled boolean Pass `true` to loop playback indefinitely
HSVideo
Self for chaining
HSVideo.fromURLs(["~/Movies/clip.mp4"]).loop(true).play()