🗄️ Video Player Store
VideoPlayerStore
is a centralized state store that powers the ZezoOTT Video Player.
It manages playback state, tracks, UI controls, analytics, and content navigation.
It works as a single source of truth for values coming from:
- 🎬 API responses (e.g.,
IContentData
, media metadata, track info) - 🎮 User interactions (play/pause, track selection, skip intro, etc.)
🚀 Core Features
- Manage playback state: current time, duration, buffering, playback rate
- Handle tracks: audio, subtitles, video quality, active track
- Control UI state: controls visibility, settings modal, skip/next episode buttons
- Track content structure: playlists, seasons, active season/episode
- Support analytics: watch time, view count, error handling
🧩 Store API (Properties & Setters)
▶️ Playback State
Prop | Type | Description |
---|---|---|
currentTime | number | Current playback time in seconds. |
setCurrentTime | (value: number) => void | Update currentTime . |
duration | number | Total duration of active video. |
setDuration | (value: number) => void | Update duration . |
isPaused | boolean | Whether playback is paused. |
setIsPaused | (value: boolean) => void | Toggle pause/play state. |
isBuffering | boolean | Whether video is buffering. |
setIsBuffering | (value: boolean) => void | Update buffering state. |
playableDuration | number | Duration already buffered. |
setPlayableDuration | (value: number) => void | Update playableDuration . |
playBackRate | number | Playback speed (e.g., 1 , 1.5 ). |
playBackRateLabel | string | null | Label for speed (e.g., 1x ). |
setPlayBackRate | (rate: number, label: string) => void | Update speed + label. |
🎚️ UI & Controls
Prop | Type | Description |
---|---|---|
controlsVisible | boolean | Show/hide playback controls. |
setControlsVisible | (value: boolean) => void | Toggle controls. |
controlsTimer | number | Timer for auto-hiding controls. |
setControlsTimer | (value: number) => void | Update controls timer. |
resizeMode | EnumValues<ResizeMode> | Video scaling (contain , cover ). |
setResizeMode | (value: EnumValues<ResizeMode>) => void | Update resizeMode . |
settingsModal | { isVisible: boolean; action: SettingsAction } | State of settings modal. |
setSettingsModal | (value: { isVisible: boolean; action: SettingsAction }) => void | Update settings modal. |
🎵 Tracks
Prop | Type | Description |
---|---|---|
selectedAudioTrack | TrackSelection | null | Current audio track. |
setSelectedAudioTrack | (value: TrackSelection | null) => void | Select audio track. |
selectedSubtitleTrack | TrackSelection | null | Current subtitle track. |
setSelectedSubtitleTrack | (value: TrackSelection | null) => void | Select subtitle track. |
selectedVideoTrack | { type: SelectedVideoTrackType; value: number } | null | Current video quality. |
setSelectedVideoTrack | (value: { type: SelectedVideoTrackType; value: number } | null) => void | Select video quality. |
activeSubtitle | SubtitleTrack | null | Active subtitle data. |
setActiveSubtitle | (value: SubtitleTrack | null) => void | Update active subtitle. |
📺 Content & Playlist
Prop | Type | Description |
---|---|---|
activeTrack | MediaTrack | null | Current playing track. |
setActiveTrack | (value: MediaTrack | null) => void | Set active track. |
playList | MediaTrack[] | Full playlist of tracks. |
setPlayList | (value: MediaTrack[]) => void | Update playlist. |
currentTrackIndex | number | Index of active track. |
setCurrentTrackIndex | (value: number) => void | Set active index. |
contentSeasons | MediaSeason[] | null | All seasons for series. |
setContentSeasons | (value: MediaSeason[] | null) => void | Update seasons. |
activeSeason | MediaSeason | null | Currently active season. |
setActiveSeason | (value: MediaSeason | null) => void | Set active season. |
📊 Analytics & Misc
Prop | Type | Description |
---|---|---|
startWatchTime | number | null | Start time for resume/analytics. |
setStartWatchTime | (value: number | null) => void | Update startWatchTime . |
isViewCounted | boolean | Whether this counts as a view. |
setIsViewCounted | (value: boolean) => void | Update view count flag. |
isSkipIntroVisible | boolean | Show/hide skip intro button. |
setIsSkipIntroVisible | (value: boolean) => void | Toggle skip intro. |
isNextEpisodeVisible | boolean | Show/hide next episode button. |
setIsNextEpisodeVisible | (value: boolean) => void | Toggle next episode. |
error | string | null | Playback error. |
setError | (value: string | null) => void | Update error state. |
maxBitRate | number | null | Max bitrate for streaming. |
setMaxBitRate | (value: number | null) => void | Update bitrate. |
onLoad | OnLoadData | null | Load metadata (tracks, etc.). |
setOnLoad | (value: OnLoadData) => void | Update onLoad . |
resetStore | () => void | Reset everything to defaults. |
⚡ Usage Example
import { useVideoPlayerStore } from "@zezosoft/zezo-ott-react-native-video-player";
import React from "react";
export default function VideoPlayerExample() {
const {
setPlayList,
setActiveSeason,
setActiveTrack,
setContentSeasons,
setCurrentTrackIndex,
resetStore,
playList,
activeTrack,
activeSeason,
} = useVideoPlayerStore();
const contentData = {
id: "movie123",
type: "series",
name: "My Series",
seasons: [
{
id: "season1",
name: "Season 1",
seasonNumber: 1,
episodes: [
{
id: "ep1",
name: "Episode 1",
sourceLink: "https://example.com/ep1.mp4",
},
{
id: "ep2",
name: "Episode 2",
sourceLink: "https://example.com/ep2.mp4",
},
],
},
],
};
const setupPlayer = () => {
resetStore();
setContentSeasons(contentData.seasons);
setActiveSeason(contentData.seasons[0]);
const playlist = contentData.seasons[0].episodes.map((ep) => ({
id: ep.id,
title: ep.name,
contentId: contentData.id,
sourceLink: ep.sourceLink,
type: contentData.type,
}));
setPlayList(playlist);
setCurrentTrackIndex(0);
setActiveTrack(playlist[0]);
};
return (
<div>
<button onClick={setupPlayer}>Load Series</button>
<h3>Active Season: {activeSeason?.name}</h3>
<ul>
{playList.map((track) => (
<li key={track.id}>
{track.title} {activeTrack?.id === track.id ? "(Playing)" : ""}
</li>
))}
</ul>
</div>
);
}
📝 Notes & Best Practices
- 🔄 Always call
resetStore()
before loading new content to avoid leftover state. - 🎚️ Playback rate (
playBackRate
) requires bothrate
andlabel
— keep them in sync. - 🕹️ Controls auto-hide is managed by
controlsTimer
. Reset it on user interactions. - 🌐 Track selections (audio, subtitles, video quality) depend on available
OnLoadData
. Always null-check. - 📊 Analytics props like
startWatchTime
andisViewCounted
should be integrated with your analytics pipeline. - ⚠️ Error handling: Use
setError
to surface playback issues in UI. - 🎬 Seasons & episodes: For series content, update both
contentSeasons
andactiveSeason
before setting a playlist. - 🎯 Performance tip: Avoid frequent store updates in a render loop (e.g.,
currentTime
) unless throttled.
✍️ Created by Naresh Dhamu – Powered by ZezoSoft
Last updated on