Javascript

Youtube Embed Player API

Youtube Embed Player API

Youtube embed player is one of the Javascript Api which allows to control the YouTube the embedded video players via JavaScript. Calls can be made to play, pause, seek to a certain time in a video, set the volume, mute the player, and other useful functions.

 

Playback controls and player settings

player.playVideo() -> Play the current video.
player.pauseVideo() -> Pause the current video.
player.stopVideo() -> Stop the current video.

Playing a video in a playlist

player.nextVideo() -> Play the next video.
player.previousVideo() -> Play the current video.

Changing the player volume

player.mute() -> Mute the volume of the player.
player.unMute() -> Unmute the volume of the player.
player.isMuted() -> Check the player is muted or not.
player.setVolume(volume) -> Set the player volume. Volume range will be 0 to 100.
player.getVolume() -> Get the Player volume

Playback status

player.getPlayerState()

Returns the state of the player. Possible values are:
-1 – unstarted
0 – ended
1 – playing
2 – paused
3 – buffering
5 – video cued

Events

onStateChange

YT.PlayerState.ENDED



YT.PlayerState.PLAYING
YT.PlayerState.PAUSED
YT.PlayerState.BUFFERING
YT.PlayerState.CUED

You can use it like below

If you like this article please don’t forget to share and comment.