I'm using the react-native-video package in my React Native app, and I want to display captions/subtitles.
I tried using the textTracks and selectedTextTrack props, but the captions are not showing on the video.
import Video, { TextTrackType } from "react-native-video";
<Video
source={{ uri: "https://example.com/video.mp4" }}
style={{ width: "100%", height: 250 }}
controls
textTracks={[
{
title: "English CC",
language: "en",
type: TextTrackType.VTT,
uri: "https://example.com/subtitles.vtt",
},
]}
selectedTextTrack={{
type: "system", // also tried 'title' and 'language'
value: "English CC",
}}
/>
Put this in settings.gradle file :
include ':react-native-video-exoplayer'
project(':react-native-video-exoplayer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android-exoplayer')
and this in build.gradle of android/app :
dependencies {
implementation("com.facebook.react:react-android")
implementation 'com.google.android.exoplayer:exoplayer:2.19.1'
...
}
and it should work 😊😊
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With