0.6.1 • Published 3 years ago

react-cp-youtube v0.6.1

Weekly downloads
36
License
MIT
Repository
github
Last release
3 years ago

Information

NOTE: This is stil under development. Don't use in production.

This React component wraps custom controls around a YouTube video for better information about what the user is doing.

Preview

preview

Install

npm i react-cp-youtube

Example

import VideoPlayer, {YouTubeRef, YouTubeOptions} from "react-cp-youtube";
import 'react-cp-youtube/dist/bundle.css';

var player: YouTubeRef;

var opts = {
  autoplay: 1,
  playsinline: 1
}

...

<VideoPlayer
  playing={true}
  time={0}
  videoId={"7v6QXZWylpI"}
  options={opts}
  onTimeUpdate={(time: number, _ : boolean) => console.log("TIME UPDATE: ", rate)}
  onPlay={(_ : boolean) => console.log("PLAY")}
  onPause={(_ : boolean) => console.log("PAUSE")}
  ytRef={(ref: YouTubeRef) => (player = ref)}
/>

...

const stopPlayer = () =>{
  if(player)
    player.getInternalPlayer().stopVideo();
}

Props

Changing playing, time, rate or videoId will result in the player changing those attributes. E.g Changing time will result in the player skipping to the provided second.

nametypedescription
playingbooleanChanges the video state to either playing or paused.
timenumberSets the time in seconds.
ratenumberSets the playback rate of the video.
videoIdstringSets the id of the video currently played.
optionsYouTubeOptionsSets the YouTube iframe parameters. More information here.
disableKbbooleanIf set to true all keyboard interactions will be blocked.
ytRef(ref: YouTubeRef) => voidWill pass a reference to the js api of the iframe. More information here.
onPlaybackRateChange(rate: number) => voidIs triggered when the user changes the playback rate. (Coming soon)
onEnd() => voidIs triggered when the current video finished playing.
onTimeChange(time: number, userInitiated : boolean) => voidIs triggered when the user changes the time of the video. The userInitiated parameter indicated wheter the event was triggered by the user or by code.
onTimeUpdate(time: number, userInitiated : boolean) => voidCalled every 500ms passes current time as parameter . The userInitiated parameter indicated wheter the event was triggered by the user or by code.
onPlay(userInitiated : boolean) => voidIs triggered when the user resumes the video. The userInitiated parameter indicated wheter the event was triggered by the user or by code. (NOTE: A time change will trigger onPlay or onPause)
onPause(userInitiated : boolean) => voidIs triggered when the user pauses the video. The userInitiated parameter indicated wheter the event was triggered by the user or by code. (NOTE: A time change will trigger onPlay or onPause)
onReady() => voidCalled when the state of the player changes to ready.
onError(error: number) => voidHandles errors of the YouTube iframe.
onPlaybackQualityChange(quality: string) => voidCalled when the video quality of the player changed. Passes the new quality.
onStateChange(state: any) => voidCalled when state of the player changes. Passes the new state.

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Maximilian Mittelhammer - @maxi_maximittel - maximittel@outlook.de

Project Link: https://github.com/MaxiMittel/react-cp-youtube

0.6.1

3 years ago

0.6.0

3 years ago

0.5.2

3 years ago

0.5.0

3 years ago

0.5.1

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago