Play and download youtube videos in Unity using YoutubeExplode and Unity's VideoPlayer.
Uses for handling video and caption downloading.
-
Add a
YoutubePlayer
component on aGameObject
with aVideoPlayer
. Set the url in the inspector. TheYoutubePlayer
will follow thePlay On Awake
setting of the video player. You can also callYoutubePlayer.PlayVideoAsync
. -
In addition, you can call
YoutubePlayer.DownloadVideoAsync
to download the video to a file instead, with captions in a.srt
file format. See theDownloadYoutubeVideo
as an example. -
VideoPlayerProgress
allows to display the progress of the video, as well as seeking. -
Captions can be downloaded and displayed on a TextMesh Pro component with the
YoutubeCaptions
script. -
See
YoutubePlayer\Scenes\Player
for a complete example, andYoutubePlayer\Scenes\Panoramic
for playing a 360 video on the skybox.
UnityYoutubePlayer relies heavily on the work done in Tyrrrz/YoutubeExplode which is responsible for parsing and downloading videos and captions. This library has the following dependencies:
In addition, we use TextMesh Pro
to display captions (but this can be easily swapped to use another kind of text UI)