Getting started

This guide walks you through adding PRESTOplay for React Native to your project, initializing the SDK, and playing your first stream.

Prerequisites

  • React 18.3 or higher

  • React Native 0.76.9 or higher

  • iOS 15.1 or higher

  • Android 8.0 or higher

  • A Castlabs license key (create one)

Note

PRESTOplay for React Native is regularly updated to support the latest stable version of React Native. It’s compatible with the interoperability layer of the new bridgeless architecture.

Install the SDK

npm install --save @castlabs/react-native-prestoplay

Android setup

Add the Castlabs repository to ./android/build.gradle. Keep this order of repository declarations for the best build times:

allprojects {
  repositories {
    google()
    mavenCentral()
    maven { url 'https://mvn.players.castlabs.com/' }
  }
}

iOS setup

Note

PRESTOplay for React Native is distributed as a dynamic library. Static linkage isn’t supported.

Add the Castlabs repository in ./ios/Podfile:

source 'https://github.com/castlabs/Specs.git'

Web setup

Add the peer dependencies in package.json:

"dependencies": {
  "react-native-web": "~0.19.6",
  "@castlabs/prestoplay": "6.36.0",
  "mux.js": "6.3.0"
}

Initialize the SDK and start playback

Call Sdk.initialize() once during your application’s lifecycle, with the license keys for your application ID. Then use the PlayerProvider and PlayerView components to render the player:

import React from "react";
import { Platform, SafeAreaView } from "react-native";
import {
  Sdk,
  ContentType,
  PlayerProvider,
  PlayerView,
} from "@castlabs/react-native-prestoplay";

Sdk.initialize({
  licenseKey: Platform.select({
    ios: () => (Platform.isTVOS ? "my-tvos-key" : "my-ios-key"),
    android: () => "my-android-key",
    web: () => "my-web-key",
    default: () => {
      throw new Error(`Unsupported platform: ${Platform.OS}`);
    },
  })(),
});

export default function App() {
  const playerConfig = {
    autoPlay: true,
    source: {
      url: "https://demo.cf.castlabs.com/media/prestohls/master.m3u8",
      type: ContentType.Hls,
    },
  };

  return (
    <SafeAreaView>
      <PlayerProvider playerConfig={playerConfig}>
        <PlayerView />
      </PlayerProvider>
    </SafeAreaView>
  );
}

Sdk.initialize() must be called before any player component is rendered. The PlayerProvider creates and manages the underlying player, and PlayerView renders the video surface.

Next, see Player basics for the player components and hooks, and Demo application for a complete application you can build and run.

Next topic: Demo application
Previous topic: PRESTOplay for React Native