API Reference
Welcome to the VP Real-Time Player API Reference. This section outlines the available methods and configuration options for integrating the VP Real-Time Player into your applications. The API provides a variety of features for controlling playback, handling events, and configuring player behavior.
Constructor
const player = vpRealtimePlayer(elementId);
elementId
(string, required): ID of the HTML container where the player will be rendered. This is a required parameter and should correspond to theid
of an HTML element in your page.
Methods
setup(streamUrl, options, config)
Initializes the player with the given stream URL, options, and configuration.
streamUrl
(string, required): URL of the video stream.options
(object, optional): Player options. Default:{ progressUpdateTime: 750 }
.config
(object, optional): Player configuration. Default:size
(object):{ width: "100%", height: "100%" }
controls
(boolean): Enable/disable native controls (default: true).
play()
Starts video playback.
pause()
Pauses video playback.
stop()
Stops video playback and resets the player.
restart()
Restarts video playback.
destroy()
Destroys the player instance and cleans up resources.
setVolume(volume)
Sets the player volume.
volume
(number): Value between 0 (mute) and 1 (full volume).
on(eventName, callback, options)
Adds an event listener to the player.
eventName
(string): Name of the event.callback
(function): Function to execute when the event is triggered.options
(object): Event listener options.
off(eventName, callback)
Removes a specific event listener from the player.
Events
channelLive
Fired when the stream changes to a live status.
channelOffline
Fired when the stream changes to an offline status.
Example: Live Stream Status Detection
Here's an example of how to detect when the stream goes live or offline:
const player = vpRealtimePlayer("video-container");
const streamUrl = "ws://your-stream-url.com/stream";
player.setup(streamUrl);
// Listen for live/offline status events
player.on("channelLive", () => console.log("Stream is live"));
player.on("channelOffline", () => console.log("Stream is offline"));
Example: Destroy Player
To destroy the player instance and clean up resources:
const player = vpRealtimePlayer("video-container");
// Destroy the player instance
player.destroy();