admin管理员组文章数量:1415119
i am trying to add subtitles in React Player ponent , Here is the code for react player ponent
<ReactPlayer
url={vidData.media[0]}
controls={true}
width={"100%"}
height={"auto"}
playing={playVid}
muted={true}
className="react-workout-player"
config={{
file: {
attributes: {
crossOrigin: "true",
},
tracks: [
{
kind: "subtitles",
src: ".vtt",
srcLang: "en",
default: true,
},
],
},
}}
/>
i cant understand what i am doing wrong as they are not appearing on the video. kindly help
i am trying to add subtitles in React Player ponent , Here is the code for react player ponent
<ReactPlayer
url={vidData.media[0]}
controls={true}
width={"100%"}
height={"auto"}
playing={playVid}
muted={true}
className="react-workout-player"
config={{
file: {
attributes: {
crossOrigin: "true",
},
tracks: [
{
kind: "subtitles",
src: "https://prod.fitflexapp./files/captions/2021/11/18/23-b2j0oOsJ.vtt",
srcLang: "en",
default: true,
},
],
},
}}
/>
i cant understand what i am doing wrong as they are not appearing on the video. kindly help
Share Improve this question edited Aug 5, 2022 at 5:20 Hamza Manan asked May 11, 2022 at 12:31 Hamza MananHamza Manan 5201 gold badge6 silver badges17 bronze badges 2- Does this Answer help you? – VC.One Commented May 11, 2022 at 23:42
- this doesnt work either – Hamza Manan Commented May 12, 2022 at 6:28
1 Answer
Reset to default 2Create a State for an array For your subtitles
const [captions_arr, setCaptions] = useState([]);
yout captions_arr should have objects like this
{kind: 'subtitles', src: 'subs/subtitles.en.vtt', srcLang: 'en', default: true},
Extract the part which you need from this array , I mapped it in a new Array
var mySubtitle_arr= captions_arr.map((v) => ({
kind: v.kind,
src: v.src,
srcLang: v.file_lang_code,
}));
After Mapping pass this array to your react Player ponent
<ReactPlayer
config={{
file: {
attributes: {
crossOrigin: "true",
},
tracks: mySubtitle_arr,
},
}}
url={'YOUR_VIDEO_URL'}
controls={true}
width={"100%"}
height={"auto"}
playing={'YOUR_PLAYING_STATE'}
muted={true}
/>
本文标签: javascriptAdding subtitles in React PlayerStack Overflow
版权声明:本文标题:javascript - Adding subtitles in React Player? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745223840a2648516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论