Youtube Player Widget
-
Introduction
You can add a Youtube video player onto the stage, and play any Youtube video in your project. Note that you are responsible for making sure the videos you play are kids-friendly, otherwise your CreatiCode account and all your projects will be deleted immediately.
To use the Youtube video player, you need to add the “widget” extension first:
Add The Youtube Player
You can use this block to add a Youtube player to the stage:
- Youtube Video URL: You can copy the URL of any Youtube video into this input box. Note that you need to use the right button of the mouse to get the pop-up menu for “copy” and “paste”:
- Center Position: the position of the center point of the video player. If you want the video to appear in the center, then you should use x = 0 and y = 0.
- Size of Video Window: the width and height of the player window. Note that it should be at most 480 wide and 360 high if you want it to fit into the stage window.
- Widget Name: You can name this video player. After the video player is added to the stage, It will appear in the dropdown selection of other related blocks, so you can use this name to control this video player (such as making it start or stop)
- Background or Foreground: This input controls whether the video player window will cover other objects on the stage. When you choose “background”, the video will serve as a background, and other sprites or drawings will appear above the video; if you choose “foreground”, then the video will cover up other objects on the stage except for other widgets. In addition, if the video is in the background, then the user will not be able to manually play or stop the video.
Video Player Controls
After the video player has been added to the stage, you can use this block to send commands to the player. You can specify which player to control using the “Please select” dropdown.
-
start: start playing the video after it has loaded. Note that the video will not start by itself after it’s added to the stage. You have to use this block to start playing the video.
-
pause: stop the video at its current time. If you run “start” after a “pause”, then the video will continue from this point.
-
stop: stop the video and reset the video time. If you start the video after stopping it, the video will start playing from the very beginning.
-
mute: make the video play in silent mode, so no sound is generated.
-
unmute: restore the video back to its normal sounds
Seek to a Video Time
You can jump to any time point into the video using the “seek to” block:
The first input allows you to specify the number of seconds. For example, if you want to skip the first 2 minutes of a video, you can seek to 120 seconds.
Current Video Time
You can also find out the current time of the video using this reporter block. It will tell us the number of seconds since the beginning of the video.
For example, suppose you want to stop the video automatically after it has played past the first 1 minute, then you can wait for when the video time is more than 60 seconds: