Skip to content

How to Use?

To utilize the JetstreamPlayer class effectively within your web application, follow these steps:

1. Include the Source Code

Ensure that you have access to the source code containing the JetstreamPlayer class definition.

2. Instantiate the JetstreamPlayer

To create a new instance of the JetstreamPlayer, use the constructor provided by the class. Pass in the necessary parameters:

typescript
const player = new JetstreamPlayer('#video-container', {
  mediaId: 'jsv:xxxxxxxxxx',
  playerId: 'jsp:xxxxxxxx',
  width: '640px',
  height: '360px',
  sticky: true,
  events: {
    play: () => {
      console.log('Video played');
    },
    pause: () => {
      console.log('Video paused');
    },
    // Add more event listeners as needed
  },
});

3. Interacting with the Player

Once the player is instantiated, you can interact with it using the provided methods:

  • play(): Initiates playback of the video.
  • pause(): Pauses the currently playing video.
  • mute(): Mutes the audio of the video.
  • unmute(): Unmutes the audio of the video.
  • seekTo(seconds: number): Seeks the video to the specified time in seconds.
  • playNext(): Plays the next video in a playlist, if available.
  • playPrev(): Plays the previous video in a playlist, if available.
  • isMuted(): Returns a Promise that resolves with a boolean indicating whether the video is muted.
  • isPaused(): Returns a Promise that resolves with a boolean indicating whether the video is paused.
  • getVideoCurrentTime(): Returns a Promise that resolves with the current playback time of the video in seconds.
  • getDuration(): Returns a Promise that resolves with the total duration of the video in seconds.
  • dispose(): Disposes of the player instance and removes event listeners.
typescript
// Example usage
player.play();
player.seekTo(30);
player.pause();

4. Handling Events

You can register event listeners to respond to various player events, such as when the video starts playing or when it pauses. These event listeners can be specified during initialization in the events option.

typescript
const player = new JetstreamPlayer('#video-container', {
  mediaId: 'jsv:xxxxxxxxxx',
  playerId: 'jsp:xxxxxxxx',
  width: '640px',
  height: '360px',
  events: {
    play: () => {
      console.log('Video played');
    },
    pause: () => {
      console.log('Video paused');
    },
    // Add more event listeners as needed
  },
});

5. Cleanup

Remember to dispose of the player instance when it is no longer needed to free up resources and remove event listeners.

typescript
player.dispose();

By following these steps, you can seamlessly integrate the JetstreamPlayer into your web application and provide users with an intuitive video playback experience.