Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3712

YouTube API load video failure

$
0
0

Helllo all ,

I am building a music app with React using the YouTube DATA API v3.

I build 2 diffrent ways the first one request for the videoId from youtube and then playing the songs - Worked

And the second one get the video ID as a prop and just suppoesd to play the song without sending any requesy to You tube but for some reason the second option is not working

This is the code that not working

its seems that the player is not created at all for some reason its not reach the "onReady"

`const loadYouTubePlayer = () => {

  playerRef.current = new window.YT.Player("youtube-player", {    height: "0", // Hide the video    width: "0", // Hide the video    videoId: videoId,    playerVars: {      autoplay: 0,      controls: 0,      modestbranding: 1,    },    events: {      onReady: (event) => {        const player = event.target;        console.log(player)        setDuration(player.getDuration());      },      onStateChange: (event) => {        if (event.data === window.YT.PlayerState.PLAYING) {          setIsPlaying(true);        } else {          setIsPlaying(false);        }      },    },  });};`

Viewing all articles
Browse latest Browse all 3712

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>