8000 GitHub - Woke-Mind/woke-words · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

woke-words

notes

initally co-pilot recommended iframe using url param enablejsapi=1
but this did not start video when runnning from host,
video started ok running locally
switch to YT.Player
[x] re-factor into shared create_video_player in js/video_player.js
<iframe
  src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1&origin=https://<username>.github.io"
  allowfullscreen
></iframe>

  src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1&origin=https://woke-mind.github.io"

https://woke-mind.github.io/woke-words/timer/

YouTube Embed and enablejsapi Parameter

This project includes embedded YouTube videos using <iframe> elements. The enablejsapi=1 URL parameter is used to enable the YouTube IFrame Player API, which allows JavaScript to control the video playback.

Key Points:

  • enablejsapi=1: This parameter must be included in the video URL to allow JavaScript to interact with the YouTube player.
  • JavaScript Control: With the API enabled, you can send commands (e.g., play, pause) to the video player using postMessage.

Example:

<iframe id="example-video" src="https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1" allowfullscreen></iframe>

JavaScript Example:

const iframe = document.getElementById('example-video');
const player = iframe.contentWindow;
player.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');

Additional Commands with postMessage

The postMessage API allows you to send various commands to the YouTube player. Below are some commonly used commands:

  • playVideo: Starts video playback.
  • pauseVideo: Pauses video playback.
  • stopVideo: Stops video playback.
  • seekTo(seconds, allowSeekAhead): Seeks to a specific time in the video. The allowSeekAhead parameter determines whether the player can make a network request to fetch more data if needed.
  • mute: Mutes the video.
  • unMute: Unmutes the video.
  • setVolume(volume): Sets the volume. The volume parameter is a number between 0 and 100.
  • getVolume: Retrieves the current volume.
  • getPlayerState: Retrieves the current state of the player (e.g., playing, paused, buffering).
  • getCurrentTime: Retrieves the current playback position in seconds.

References:

Releases

Packages

Contributors

Languages

0