HSVideo
TypeBridge 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
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 |
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
clip.play()
pause() -> HSVideo
Pause playback
pause() -> HSVideo
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 |
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.fromURLs(["~/Movies/clip.mp4"]).loop(true).play()