Feature Deep Dive

Video Player — YouTube, PiP & Live Controls

A3KM Studio's video player embeds YouTube videos using the YouTube IFrame API — giving you autoplay, Picture-in-Picture, like/share bookmarking, and realtime related-video suggestions, all inside the site's own branded UI.

YouTube IFrame API দিয়ে ভিডিও embed করা হয় — PiP, like toggle, related videos, এবং description section সহ। Real-time YouTube Data API v3 দিয়ে views, likes, এবং thumbnails fetch হয়।

YouTube IFrame Mobile PiP + Fallback YT Data API v3 Bookmark Zone Gestures Landscape FS
What is it?

YouTube Player — How it works

The video player is not a custom HTML5 player — it is a fully-featured YouTube embed powered by the YT IFrame API with extra controls layered on top by A3KM's own JS.

YouTube IFrame API
YT.Player object loads via async script injection. 5-second timeout fallback to a raw <iframe> if the API does not load.
Picture-in-Picture
Enabled via the allow="picture-in-picture" attribute on the iframe. Works on supported browsers natively — no custom JS needed.
Like Toggle
Client-side isLiked boolean state. Tapping the like button toggles heart icon color — stored per-session.
Share / Copy
Share button copies the video URL to clipboard. Web Share API used on mobile where available.
API Data Enrichment
YouTube Data API v3 fetches real view counts, like counts, and high-res thumbnails. API key stored in localStorage (youtube_api_key).
Related Videos
renderRelatedVideos() displays cards below the player. Thumbnails come from YouTube CDN: img.youtube.com/vi/[ID]/mqdefault.jpg
Anatomy

Player UI Breakdown

Every element visible when watching a video — from the player to the action bar below.

Videos
Video Blogs
PiP
02:34 / 18:07
Share
Save
YT
Description
In this video we explore Arduino sensor integration with deep dive on I2C protocol and libraries...
Watch
List
Search
1

YouTube IFrame Player

Embedded using YT.Player API. Has autoplay=1, rel=0, modestbranding=1, playsinline=1. The allow attribute enables PiP.

2

Progress Bar

Native YouTube progress bar inside the iframe. Red filled bar matches A3KM's color scheme.

3

Action Row

Like (isLiked toggle), Share, Bookmark (localStorage), and open-in-YouTube buttons. Rendered outside the iframe by A3KM JS.

4

Description Section

descriptionSection div. Shows the content's own description field — not pulled from YouTube, stored in content.json.

5

Related Videos Rail

renderRelatedVideos() populates this list. Thumbnails from YouTube CDN — no API call needed for these.

6

PiP Badge

Indicates Picture-in-Picture is available. Tap the browser's PiP button while the video is playing to float it.

Touch Controls

Zone-Based Gesture System

The video player uses a 3-zone swipe gesture system on mobile — each horizontal region of the player screen has its own control. A transparent .vp-gesture layer sits over the entire player with touch-action: none to intercept all touch events before YouTube handles them.

Gesture Zones — Player Overlay
LEFT ⅓
Brightness
↑ swipe up/down
CENTER
Fullscreen
↑ swipe up
RIGHT ⅓
Volume
↑ swipe up/down
All zone swipes use requestAnimationFrame batching for smooth 60fps updates
Brightness Zone (Left)
Swipe up/down in the left ⅓ of the player to adjust screen brightness. Requires browser brightness API — shows overlay indicator.
Volume Zone (Right)
Swipe up/down in the right ⅓ to control volume via player.setVolume(). Uses RAF batching for smooth 60fps response — no jank.
Fullscreen Zone (Center)
Swipe up in the center of the player triggers fullscreen. Swipe down exits fullscreen. Single-finger gesture, threshold ≥30px.
Single Tap → Controls Only
A single tap on the gesture layer shows/hides the control bar — it does not play or pause the video. Prevents accidental pause.
Landscape Fullscreen
When entering landscape FS, body.vp-landscape-fs class is added. CSS hides all page siblings except #vpWrapper — clean immersive view.
PiP Smart Fallback
If PiP is requested before the player is ready (!playerReady), a mini-remote overlay appears instead of silently failing. Lets you control playback instantly.
touch-action: none

The .vp-gesture overlay has touch-action: none set via CSS. This prevents the browser's default touch behaviors (scroll, pinch-zoom, double-tap-zoom) from conflicting with the zone gesture recognition — especially important in landscape orientation.

Load Flow

How the Player Initializes

From page load to first frame — what happens behind the scenes.

1

Page opens with video ID from URL

The viewer reads the ?id= query parameter. Matches against the loaded videos array from content.json.

2

YT IFrame API script injected

A <script src="https://www.youtube.com/iframe_api"> tag is dynamically appended to document.head.

3

5-second fallback timer starts

If onYouTubeIframeAPIReady hasn't fired within 5 seconds, a plain <iframe> is inserted as fallback — no API dependency.

4

YT.Player() created

Called with playerVars: { autoplay:1, rel:0, modestbranding:1, playsinline:1 }. The allow attribute includes picture-in-picture.

5

Description + Related rendered

descriptionSection and relatedSection divs are populated with content data. renderRelatedVideos() uses YouTube CDN thumbnails.

6

API enrichment (if key available)

If youtube_api_key exists in localStorage, a YouTube Data API v3 call fetches view counts and likes. formatViews() and formatLikes() format the numbers.

Shortcuts

Keyboard Controls

These are native YouTube shortcuts that work inside the embedded player.

KeyActionNotes
Space / KPlay / PauseClick the player first to focus it
FFullscreenExits with Escape
← →Seek ±5 secondsHold for faster seek
↑ ↓Volume ±5%While player is focused
MMute / Unmute
0–9Jump to 0%–90%Number keys seek to that percentage
, / .Frame step ±1When paused
Comparison

Mobile vs Desktop

The video player behaves differently across platforms.

Mobile
  • playsinline=1 — plays inside the page, not fullscreen auto-launch
  • Zone gestures: left⅓ brightness, right⅓ volume, center swipe = fullscreen
  • Single tap shows controls only — no accidental pause
  • Landscape FS hides all page UI via body.vp-landscape-fs
  • PiP fallback mini-remote if player not yet ready
  • Touch to tap Like / Share / Bookmark
  • Expandable description section
  • No keyboard shortcuts (no keyboard)
Desktop
  • Full keyboard shortcut set works
  • PiP via right-click context menu or browser button
  • Larger player area — more immersive
  • Action buttons always visible below player
  • Hover effects on related video cards
  • Copy-link via Share button (Clipboard API)
Hidden Features

Lesser-Known Tricks

Thumbnail CDN shortcut

Every YouTube video's thumbnail is available at https://img.youtube.com/vi/[VIDEO_ID]/mqdefault.jpg — no API key needed. A3KM uses this for related video cards, keeping them fast and free.

5-second API fallback

If YouTube's IFrame API script doesn't load (firewall, network issue) within 5 seconds, the page automatically switches to a plain <iframe>. The video still plays — you just lose the extra JS layer.

Picture-in-Picture on mobile

While watching a video, leave the app or switch tabs. The video continues floating as a PiP overlay. This works because the iframe has allow="picture-in-picture" — it's a browser-native feature, not custom code.

PiP mini-remote fallback

If you trigger PiP before the YouTube player has finished initializing (playerReady = false), a mini-remote control overlay appears automatically. This lets you pause, seek, and control volume without waiting — the overlay disappears once the main player is ready.

Single-tap doesn't pause

Unlike most video players, tapping the center of the player does not toggle play/pause. A single tap on the .vp-gesture overlay only shows or hides the control bar. To pause, use the play/pause button in the control bar itself. This prevents accidental pausing.

Like state is session-only

The isLiked flag is an in-memory JS variable — not persisted to localStorage. It resets on page refresh. This is intentional — the like button is a quick quality-signal UI element, not a tracking system.

Technical Details

Code Reference

Key File
Source JS
mobile/content-studio/video-blogs/video-viewer.js
Embed URL template
https://www.youtube.com/embed/{VIDEO_ID}?autoplay=1&rel=0&modestbranding=1&playsinline=1
iframe allow attr
accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture
Like state var
isLiked (boolean, in-memory)
API fallback timer
5000ms — then raw iframe injection
Related thumbnails
img.youtube.com/vi/[ID]/mqdefault.jpg (no API)
Enrichment key store
localStorage key: youtube_api_key
Views formatter
formatViews() — 1200 → "1.2K"
Likes formatter
formatLikes() — 4800 → "4.8K"
Gesture overlay element
.vp-gesture — touch-action: none; position: absolute; inset: 0
Gesture zones
Left ⅓ = brightness · Center = fullscreen · Right ⅓ = volume
Volume smoothing
requestAnimationFrame batch — player.setVolume() called in rAF callback
Single tap behavior
Shows/hides controls only — does not trigger play/pause
Landscape fullscreen CSS
body.vp-landscape-fs — siblings hidden, only #vpWrapper visible
PiP not-ready fallback
if (!playerReady) → show mini-remote overlay
Explore More

Other Feature Guides

More deep-dives into A3KM Studio features — shortcuts, hidden tricks, mobile vs desktop comparisons and code references.