Skip to content

Parameter bufferSizeGetter

Description

The bufferSizeGetter parameter provides the Teleport SDK with a function to read the current buffer size of the video player. This information is used by the SDK to make decisions about when and which segments to request from the peer-to-peer network or CDN, optimizing the delivery process and minimizing buffering.

Importance of Buffer Size

Accurate knowledge of the player's buffer size is critically important for the Teleport SDK. This information is used to make decisions about the content loading strategy, allowing the SDK to more effectively manage requests to the peer-to-peer network or CDN, preventing excessive loading (which saves traffic) and insufficient loading (which prevents buffering).

When is it necessary?

It is always recommended to specify the bufferSizeGetter function if your player provides access to buffer size information. This allows the Teleport SDK to adapt maximally to the player's state.

Example Usage

js
let player = new shaka.Player(video); // Example of Shaka Player initialization

let tlprt = await teleport.initialize({
    apiKey: "YOUR_API_KEY", // Your API key
    loader: {
        type: "PLUGIN_ID", // Identifier of the player plugin used
        params: {
            // Function to get the current buffer size of the player
            bufferSizeGetter: () => {
                // Example of getting buffer information from Shaka Player
                let playhead = player.getPlayheadTimeAsDate().getTime();
                let presentation = player.getPresentationStartTimeAsDate().getTime();
                let start = (playhead - presentation) / 1000; // Current playback position in seconds

                let buf = player.getBufferedInfo();
                let end = buf && buf.video && buf.video[0] && buf.video[0].end || 0; // End of buffered range

                // Return buffer size in seconds
                return end > start ? end - start : 0;
            }
        }
    }
});