YoutubeSimplifiedRequest
is a Unity script that simplifies YouTube video playback directly in Unity, supporting multiple video qualities, formats, and features like 360° and 3D videos.
- Unity 2019.4 or higher
- Unity Video module installed
- Newtonsoft.Json (for JSON parsing)
- SimpleJSON (for JSON parsing)
youtubeUrl
: URL of the YouTube video to playvideoQuality
: Video quality (Standard, Hd, Fullhd, Uhd1440, Uhd2160)is360
: Whether the video is 360 degreesvideoFormat
: Video format (Mp4 or Webm)
autoPlayOnStart
: Automatically plays on startstartFromSecond
: Starts playback from a specific timeshowThumbnailBeforeVideoLoad
: Shows thumbnail before video loadscustomPlaylist
: Enables custom playlistautoPlayNextVideo
: Automatically plays next video in playlist
playUsingInternalDevicePlayer
: Uses native mobile device video playerloadYoutubeUrlsOnly
: Only loads URLs without playingis3DLayoutVideo
: Enables 3D modelayout3d
: 3D layout type (SideBySide, OverUnder, etc.)mainCamera
: Main camera for renderingvideoPlayer
: VideoPlayer component for videoaudioPlayer
: VideoPlayer component for audio (HD+ qualities)
PlayYoutubeVideo(string videoUrl)
: Starts video playbackPlay()
: Resumes paused playbackPause()
: Pauses playbackStop()
: Stops playback completely
SkipToPercent(float pct)
: Skips to specific percentage of videoTrySkip(PointerEventData eventData)
: Attempts to skip based on UI event
The script triggers several events through the YoutubeVideoEvents
component:
OnVideoReadyToStart
: When video is ready to startOnVideoStarted
: When playback beginsOnVideoPaused
: When video is pausedOnVideoFinished
: When video endsOnYoutubeUrlAreReady
: When URLs are ready (loadYoutubeUrlsOnly mode)YoutubeTimedEvent
: Array of events that trigger events at specific video time and optionally pause the video waiting for an action from the user.
The system allows adding time-based events during video playback. You can configure specific actions to trigger when the video reaches predefined timestamps without additional coding. These events are triggered when the current playback time reaches the preset values.
- Extracts video ID from provided URL
- Makes request to YouTube API to get stream URLs
- Processes response and extracts video/audio URLs
- Configures VideoPlayers with obtained URLs
- Manages synchronization between video and audio (for HD+ qualities)
- Standard (360p): Uses single VideoPlayer with integrated audio
- Higher qualities: Uses two VideoPlayers (one for video, one for audio) with manual synchronization
- For 360° videos, the script automatically adjusts the skybox
- 3D videos require specially configured materials
- On mobile devices, may use native player for better performance
- Audio/video synchronization in high qualities is experimental
- Qualities above 720p may have synchronization issues
- Some restricted videos may not work
- Requires internet connection to obtain stream URLs
- You simply can use our prefab with the YoutubePlayer script or you can create custom functionalities if you want using the requester script (YoutubeSimplifiedRequest[You need the setup the callbacks])
// Basic Inspector setup:
// - Set youtubeUrl
// - Configure desired videoQuality
// - Assign videoPlayer and audioPlayer (if HD+)
// To play programmatically:
GetComponent<YoutubeSimplifiedRequest>().PlayYoutubeVideo("https://youtu.be/VIDEO_ID");