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
Declaration
HSVideo.fromURLs(urls) -> HSVideo
Parameters
| Name | Type | Description |
|---|---|---|
| urls | string[] | Each entry is a local file path (`~` is expanded) or a remote URL string |
Returns
HSVideo
An HSVideo object, or null if the list is empty or an entry couldn't be resolved
Example
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
Declaration
play() -> HSVideo
Returns
HSVideo
Self for chaining
Example
clip.play()
pause() -> HSVideo
Pause playback
Declaration
pause() -> HSVideo
Returns
HSVideo
Self for chaining
Example
clip.pause()
seek(seconds) -> HSVideo
Seek to a specific position
Declaration
seek(seconds) -> HSVideo
Parameters
| Name | Type | Description |
|---|---|---|
| seconds | number | The position to seek to, in seconds |
Returns
HSVideo
Self for chaining
Example
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.
Declaration
loop(enabled) -> HSVideo
Parameters
| Name | Type | Description |
|---|---|---|
| enabled | boolean | Pass `true` to loop playback indefinitely |
Returns
HSVideo
Self for chaining
Example
HSVideo.fromURLs(["~/Movies/clip.mp4"]).loop(true).play()