反应视频播放器轮播不显示视频

react video player carousel not showing videos

我正在使用 react-elastic-carouselreactjs-media npm 包来显示 YouTube 视频轮播。但是我的视频没有显示,如果我点击一个我得到 "Error appeared . Try again later "

enter image description here

我的代码:

VideoSlider.js

import Carousel from "react-elastic-carousel";
import {YoutubePlayer} from 'reactjs-media';

export default function VideoSlider() {


  const links = [
    'https://www.youtube.com/watch?v=_ng_bVJMm88',
    'https://www.youtube.com/watch?v=5Zmx5D7dOYA&feature=emb_title',
    'https://www.youtube.com/watch?v=nKzXUTvn2es',
    'https://www.youtube.com/watch?v=Wk97ev-M2Nw',
    'https://www.youtube.com/watch?v=FZta8t2L1pk',
    'https://www.youtube.com/watch?v=BOmSrKRWJS0',
  ]


  const breakPoints  = [
    { width: 1, itemsToShow: 1 },
    { width: 550, itemsToShow: 2, itemsToScroll: 2 },
    { width: 768, itemsToShow: 2 },
    { width: 1200, itemsToShow: 3 }
  ];


  return (
    <div className="bg-FQAItem  h-84 p-4">
        <div className="carousel-wrapper">
          <Carousel breakPoints={breakPoints} isRTL ={false} >
            {links.map((item,index) => (
                <YoutubePlayer  src="https://www.youtube.com/watch?v=5Zmx5D7dOYA&feature=emb_title"  height={350} key = {index}/>
            ))}
          </Carousel>
        </div>
    </div>
  )

}

非常感谢你的帮助。

您的视频linkurl有误。

正确的 URL 应该是 -> https://youtu.be/5Zmx5D7dOYA

而不是

https://www.youtube.com/watch?v=5Zmx5D7dOYA&feature=emb_title

建议视频link通过右击视频来拍摄,而不是从浏览器地址栏复制。

参考:SRC prop note here --> https://cranom.com/reactjs-media/api/youtube-player-props