Skip to main content

Player Functions

Basic usage

import React, {useRef} from 'react';
import PeertubePlayer, {PeertubeIframeRef} from "react-native-peertube-iframe";

const App = () => {

const playerRef = useRef();

// typescript
// const playerRef = useRef<PeertubeIframeRef>(null);

return (
<PeertubePlayer
ref={playerRef}
height={400}
width={400}
videoUrl={'https://vidz.julien.ovh/videos/embed/105fd6ef-3048-43c3-b877-fdb8aaab11d5'}
/>

<Button
title="log details"
onPress={() => {
playerRef.current?.getCurrentTime().then(
currentTime => console.log({currentTime})
);

playerRef.current?.getDuration().then(
getDuration => console.log({getDuration})
);
}}
/>
);
};

getAvailableCaption

function(): Promise[Array[PeertubeCaption]]

retrieve in a promise the list of available caption for the ongoing content. PeertubeCaption is composed of an id, a label, a src (the subtitle url) and a mode 'disabled' or 'showing'.


getAvailablePlaybackQualities

function(): Promise[Array[PeertubePlaybackQuality]]

returns a promise that resolves to a list of available playback quality.

PeertubePlaybackQuality represent a video selectable track with and id, a labal, the resolution and a boolean indicating if the tracks is selected.


getAvailablePlaybackRates

function(): Promise[Array[Number]]

returns a promise that resolves to a list of available playback rates.

The array of numbers are ordered from slowest to fastest playback speed. Even if the player does not support variable playback speeds, the array should always contain at least one value (1).


getCurrentTime

function(): Promise[Number]

returns a promise that resolves to the elapsed time in seconds since the video started playing.


getDuration

function(): Promise[Number]

returns a promise that resolves to the total duration of the video.

If the currently playing video is a live event, the getDuration() function will resolve the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.

note

getDuration() will return 0 until the video's metadata is loaded, which normally happens just after the video starts playing.


getPlaybackRate

function(): Promise[Number]

returns a promise that resolves to the current playback rate of the video.

The default playback rate is 1, which indicates that the video is playing at normal speed. Playback rates may include values like 0.25, 0.5, 1, 1.5, and 2.


getVolume

function(): Promise[Number]

returns a promise that resolves to the player's current volume, an integer between 0 and 100. Note that getVolume() will return the volume even if the player is muted.


isMuted

function(): Promise[Boolean]

returns a promise that resolves to true if the video is muted, false if not.


seekTo

function(seconds:Number):Void

Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, etc.), the player will play the video. The seconds parameter identifies the time to which the player should advance.


setCaption

function(id:String):Void

Set the current playback caption (subtitle track). Pass the id of the track retrieved with getAvailableCaption function Setting an invalid id, will disable caption.


setRate

function(rate:Number):Void

Set the current playback rate. You can list the available playback rates with getAvailablePlaybackRates


setPlaybackQuality

function(index:Number):Void

Set the current resolution / Playback quality to specified index. You should list the available resolutions with getAvailablePlaybackQualities or by listening on onPlaybackQualityChange.


setVolume

function(volume:Number):Void

Set the current playback volume. Volumes is defined bewen 0 (muted) and 1 (100% volume)