Skip to main content

youtube-embed

ai-research-agent / interface/youtube-embed

Interface

embedYoutubePlayer()

function embedYoutubePlayer(): YouTubePlayer

Creates video player wrapping YouTube IFrame Player API in a div element with the specified ID.

Returns

YouTubePlayer

An object containing the YouTube API functionality.

Example

// <div id="player"></div>
const YT = embedYoutubePlayer();
new YT.Player('player', {
height: '360',
width: '640',
videoId: 'dQw4w9WgXcQ',
events: {
'onReady': onPlayerReady,
'onStateChange': null,
'onTimeChange': onTimeChange,
}
});
function onPlayerReady(event) {
event.target.playVideo();
}
function onTimeChange(time) {
console.log(time)
}

Other

YouTubePlayer

Properties

addEventListener
addEventListener: Function;

Adds an event listener.

cuePlaylist
cuePlaylist: Function;

Cues a playlist.

cueVideoById
cueVideoById: Function;

Cues a specified video.

cueVideoByUrl
cueVideoByUrl: Function;

Cues a video by URL.

destroy
destroy: Function;

Destroys the player instance.

getAvailablePlaybackRates
getAvailablePlaybackRates: Function;

Gets available playback rates.

getCurrentTime
getCurrentTime: Function;

Gets the current playback time.

getDuration
getDuration: Function;

Gets the video duration.

getIframe
getIframe: Function;

Gets the player iframe element.

getPlaybackRate
getPlaybackRate: Function;

Gets the playback rate.

getPlayerState
getPlayerState: Function;

Gets the current player state.

getPlaylist
getPlaylist: Function;

Gets the current playlist.

getPlaylistIndex
getPlaylistIndex: Function;

Gets the index of the current playlist item.

getVideoEmbedCode
getVideoEmbedCode: Function;

Gets the embed code for the current video.

getVideoLoadedFraction
getVideoLoadedFraction: Function;

Gets the fraction of the video loaded.

getVideoUrl
getVideoUrl: Function;

Gets the URL of the current video.

getVolume
getVolume: Function;

Gets the player volume.

isMuted
isMuted: Function;

Checks if the player is muted.

loadPlaylist
loadPlaylist: Function;

Loads a playlist.

loadVideoById
loadVideoById: Function;

Loads a specified video.

loadVideoByUrl
loadVideoByUrl: Function;

Loads a video by URL.

mute
mute: Function;

Mutes the player.

nextVideo
nextVideo: Function;

Plays the next video in the playlist.

pauseVideo
pauseVideo: Function;

Pauses the currently playing video.

playVideo
playVideo: Function;

Plays the currently loaded video.

playVideoAt
playVideoAt: Function;

Plays a specific video in the playlist.

previousVideo
previousVideo: Function;

Plays the previous video in the playlist.

removeEventListener
removeEventListener: Function;

Removes an event listener.

seekTo
seekTo: Function;

Seeks to a specified time in the video.

setLoop
setLoop: Function;

Sets whether the player should loop playlists.

setPlaybackRate
setPlaybackRate: Function;

Sets the playback rate.

setShuffle
setShuffle: Function;

Sets whether playlists should be shuffled.

setSize
setSize: Function;

Sets the player size.

setVolume
setVolume: Function;

Sets the player volume.

stopVideo
stopVideo: Function;

Stops the currently playing video.

unMute
unMute: Function;

Unmutes the player.