Play and download youtube videos in Unity using YoutubeExplode and Unity's VideoPlayer.
Uses for handling video and caption downloading.
-
Add a
YoutubePlayercomponent on aGameObjectwith aVideoPlayer. Set the url in the inspector. TheYoutubePlayerwill follow thePlay On Awakesetting of the video player. You can also callYoutubePlayer.PlayVideoAsync. -
In addition, you can call
YoutubePlayer.DownloadVideoAsyncto download the video to a file instead, with captions in a.srtfile format. See theDownloadYoutubeVideoas an example. -
VideoPlayerProgressallows to display the progress of the video, as well as seeking. -
Captions can be downloaded and displayed on a TextMesh Pro component with the
YoutubeCaptionsscript. -
See
YoutubePlayer\Scenes\Playerfor a complete example, andYoutubePlayer\Scenes\Panoramicfor 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)
