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

Is there a way I can access event's related to a youtube player's video progress bar embedded video iframe with npm react-youtube?

$
0
0

I am trying to access the video progress bar with the npm react-youtube library. I would like to basically be able to know when the current time stamp is changed, sort of like an onClick event or something similiar.

My goal is to notice when the user changes the current time stamp(either by scrolling along the video progress bar or just by selecting a time), and then broadcast that new time stamp to update another player's progress with a socket connection.

Below is my YouTube player

I have these imports

import io from "socket.io-client";import { useState, useEffect, useRef } from "react";import YouTube, { YouTubeProps } from "react-youtube";import { useNavigate, useParams } from "react-router-dom";

I also have this useRef here for my player:const playerRef = useRef();

<YouTube                    ref={playerRef}                    videoId={searchResponse[videoCount]} // defaults -> ''                    //id={string} // defaults -> ''                    //className={string} // defaults -> ''                    //iframeClassName={string} // defaults -> ''                    //style={object} // defaults -> {}                    //title={string} // defaults -> ''                    //loading={string} // defaults -> undefined                    //opts={obj} // defaults -> {}                    //onReady={(event) => {                    //console.log(event);                    //console.log(event.target);                    //console.log("now playing(by default)");                    //playerRef.current.internalPlayer.playVideo();                    //socket.emit("playVideo", { room: 123 });                    //}} // defaults -> noop                    onPlay={(event) => {                        console.log(event);                        console.log(event.target);                        console.log("now playing");                        event.target.playVideo();                        socket.emit("playVideo", { room: room });                    }} // defaults -> noop                    onPause={(event) => {                        console.log("now pausing", event);                        socket.emit("pauseVideo", { room: room });                    }} // defaults -> noop                    //onEnd={func} // defaults -> noop                    //onError={func} // defaults -> noop                    onStateChange={(event) => {                        console.log("now changing state", event);                        console.log("current time is: " +                                                                         event.target.getCurrentTime());                        console.log(searchResponse[videoCount]);                    }} // defaults -> noop                    //onPlaybackRateChange={func} // defaults -> noop                    //onPlaybackQualityChange={func} // defaults -> noop                />

Thank you in advance!


Viewing all articles
Browse latest Browse all 3640

Trending Articles



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