Jetstream player API methods
JetstreamPlayer class available methods
The following methods are available in this version of the library:
play()pause()mute()unmute()seekTo()playNext()playPrev()isMuted()isPaused()getVideoCurrentTime()getDuration()on()off()dispose()
This list is not exhaustive. New methods can be added to the library as needed.
To use these methods, import the JetstreamPlayer class and call them as described in the previous section.
import { JetstreamPlayer } from '@hopecloud/jetstream-player';
let player;
onMounted(() => {
player = new JetstreamPlayer('#iframe1', {
mediaId: 'jsv:xxxxxxxxxx',
});
});
player.play();play() and pause()
The play or pause method can be called for a video as well as for a playlist. We are able to interact with our videos or playlists programmatically in the same way as pressing pause or play within the iframe itself.
Autoplay policy
Before any user interaction (click, play), a programmatic play() on a video with sound will not start playback. This is the browser's autoplay policy — the same rule YouTube, Facebook, etc. face — and there is no way to bypass it.
A single user action (a click inside the iframe) lifts the restriction; after that, play() works normally. If the video or playlist is muted, play() works without any interaction.
mute()
The mute() function sets the media volume to silent.
unmute()
Unmutes the volume.
Getter methods and timeouts
isMuted(), isPaused(), getVideoCurrentTime() and getDuration() ask the player for a value and return a Promise that resolves with the reply.
Getters can time out
If the player doesn't answer within 5 seconds, the Promise rejects with a timeout error instead of hanging forever. Wrap getter calls in try/catch (or .catch()) accordingly.
isMuted()
Returns true if the player volume is muted, false if not.
seekTo(seconds: number)
Seeks the video to the specified time in seconds.
playNext() and playPrev()
The playNext or playPrev method can be called only for a playlist. Calling these methods for a simple video will do nothing. We can interact with a playlist programmatically in the same way as pressing playNext or playPrev within the playlist itself.
isPaused(): Promise<boolean>
Returns a Promise that resolves with a boolean indicating whether the video is paused.
getVideoCurrentTime(): Promise<number>
Returns a Promise that resolves with the current playback time of the video in seconds.
getDuration(): Promise<number>
Returns a Promise that resolves with the total duration of the video in seconds.
on(event, handler) and off(event, handler?)
Subscribe to player events after the instance has been created — the dynamic counterpart to the events constructor option. Both share the same registry, so listeners added either way fire together.
event is a typed PlayerEvents name; handler receives the event value:
type PlayerEvents =
| 'ready'
| 'timeupdate'
| 'play'
| 'pause'
| 'loadedmetadata'
| 'ended'
| 'volumechange'
| 'error';on() registers a listener and returns an unsubscribe function. Multiple listeners can be registered for the same event — they all fire, in registration order.
const off = player.on('timeupdate', (seconds) => {
console.log('current time', seconds);
});
// later — stop listening
off();off() removes listeners by name. Pass the same handler to remove that one listener, or omit it to remove every listener for the event:
const onPlay = () => console.log('playing');
player.on('play', onPlay);
player.off('play', onPlay); // remove just this handler
player.off('play'); // remove all 'play' handlersTIP
on() accepts the same event names as the events option, so you can mix constructor-time and runtime subscriptions freely.
dispose()
Disposes of the player instance and removes event listeners.