Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

captions not working in react-native-video

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",
  }}
/>
like image 431
Abhishek Verma Avatar asked Oct 30 '25 05:10

Abhishek Verma


1 Answers

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 😊😊

like image 87
Gaurav Mishra Avatar answered Oct 31 '25 21:10

Gaurav Mishra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!