@devix-technologies/react-gjirafa-vp-player 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +271 -0
- package/dist/react-gjirafa-vp-player.es.js +746 -626
- package/dist/react-gjirafa-vp-player.umd.js +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,6 +85,8 @@ interface VPPlayerProps {
|
|
|
85
85
|
className?: string; // Optional CSS class name for additional styling of the player
|
|
86
86
|
onClose, // Handler function triggered when the player is closed.
|
|
87
87
|
isPlayerVisible, // Flag indicating whether the player is currently visible.
|
|
88
|
+
onPlaylistData?: (videos: PlaylistItem[]) => void; // Optional callback that fires when playlist data is loaded
|
|
89
|
+
onVideoStarted?: (videoData: CurrentVideoData) => void; // Optional callback that fires when a video starts playing
|
|
88
90
|
}
|
|
89
91
|
```
|
|
90
92
|
|
|
@@ -148,6 +150,116 @@ interface VPPlayerProps {
|
|
|
148
150
|
|
|
149
151
|
- Optional flag indicating whether the player is currently visible. Controls the visibility of the player component, typically used to show or hide the player in a modal, overlay, or inline context.
|
|
150
152
|
|
|
153
|
+
### **onPlaylistData?: (videos: PlaylistItem[]) => void**
|
|
154
|
+
|
|
155
|
+
- Optional callback function that fires when playlist data is successfully loaded from the API. This is useful for:
|
|
156
|
+
- Getting a list of all videos in the playlist (including main and backup playlists)
|
|
157
|
+
- Displaying a video list/menu in your UI
|
|
158
|
+
- Pre-loading thumbnails or metadata
|
|
159
|
+
- Building custom playlist navigation
|
|
160
|
+
- **Parameters:**
|
|
161
|
+
- `videos`: Array of `PlaylistItem` objects containing video metadata (title, hlsUrl, thumbnailUrl, duration, isBackupPlaylist, mediaId)
|
|
162
|
+
- **When it fires:**
|
|
163
|
+
- Once when playlist data is fetched from API (for playlists via `playlistId`)
|
|
164
|
+
- **Example:**
|
|
165
|
+
```typescript
|
|
166
|
+
<VPPlayer
|
|
167
|
+
playerId="player"
|
|
168
|
+
projectId="agmipnzb"
|
|
169
|
+
playlistId="lzxikgjw"
|
|
170
|
+
apiKey="YOUR_API_KEY"
|
|
171
|
+
onPlaylistData={(videos) => {
|
|
172
|
+
console.log('Playlist loaded:', videos.length, 'videos');
|
|
173
|
+
console.log('Main videos:', videos.filter(v => !v.isBackupPlaylist).length);
|
|
174
|
+
console.log('Backup videos:', videos.filter(v => v.isBackupPlaylist).length);
|
|
175
|
+
// Update your UI with playlist data
|
|
176
|
+
}}
|
|
177
|
+
/>
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### **onVideoStarted?: (videoData: CurrentVideoData) => void**
|
|
181
|
+
|
|
182
|
+
- Optional callback function that fires when a video starts playing. This provides real-time information about the currently playing video. Behavior differs between player types:
|
|
183
|
+
|
|
184
|
+
**Vertical Player (Reels):**
|
|
185
|
+
- Fires on scroll (swipe up/down) to navigate between videos
|
|
186
|
+
- Fires on arrow button clicks (next/previous)
|
|
187
|
+
- Returns basic metadata from the already-loaded playlist
|
|
188
|
+
|
|
189
|
+
**Horizontal Player (Standard):**
|
|
190
|
+
- Fires on Next/Previous button clicks
|
|
191
|
+
- Fires when video ends and next video auto-plays
|
|
192
|
+
- Fetches **complete metadata from API** (`https://host.vpplayer.tech/player/{playerId}/{videoId}.json`)
|
|
193
|
+
- Returns comprehensive data including author, tags, publishDate, premium status, etc.
|
|
194
|
+
|
|
195
|
+
- **Parameters:**
|
|
196
|
+
- `videoData`: Object containing video metadata:
|
|
197
|
+
- `videoId` - Video ID
|
|
198
|
+
- `title` - Video title
|
|
199
|
+
- `description` - Video description (HTML)
|
|
200
|
+
- `file` / `hlsUrl` - Video stream URL
|
|
201
|
+
- `thumbnailUrl` - Thumbnail image URL
|
|
202
|
+
- `duration` - Video duration in seconds
|
|
203
|
+
- `videoIndex` - Index in playlist (0-based)
|
|
204
|
+
- `playlistVideoIndex` - VP Player playlist index
|
|
205
|
+
- `isBackupPlaylist` - Whether video is from backup playlist
|
|
206
|
+
- **Horizontal player additional fields:**
|
|
207
|
+
- `publishDate` - Publication date (ISO format)
|
|
208
|
+
- `projectId` - Project/entity ID
|
|
209
|
+
- `premium` - Whether video is locked/premium
|
|
210
|
+
- `author` - Video author name
|
|
211
|
+
- `tags` - Array of video tags
|
|
212
|
+
|
|
213
|
+
- **Use cases:**
|
|
214
|
+
- **Analytics tracking**: Track video views, engagement, navigation patterns
|
|
215
|
+
- **Custom UI updates**: Display current video info, progress indicators
|
|
216
|
+
- **Content recommendations**: Use tags/author to suggest related content
|
|
217
|
+
- **Monetization**: Check premium status, track ad opportunities
|
|
218
|
+
- **Social features**: Display author info, enable sharing
|
|
219
|
+
|
|
220
|
+
- **Example (Vertical Player):**
|
|
221
|
+
```typescript
|
|
222
|
+
<VPPlayer
|
|
223
|
+
playerId="vertical-player"
|
|
224
|
+
projectId="agmipnzb"
|
|
225
|
+
playlistId="lzxikgjw"
|
|
226
|
+
scriptUrl="https://host.vpplayer.tech/vertical-player/rbqcdwznd.js"
|
|
227
|
+
isReels={true}
|
|
228
|
+
apiKey="YOUR_API_KEY"
|
|
229
|
+
onVideoStarted={(videoData) => {
|
|
230
|
+
console.log('Video changed:', videoData.title);
|
|
231
|
+
console.log('Video index:', videoData.videoIndex);
|
|
232
|
+
// Track analytics, update UI
|
|
233
|
+
}}
|
|
234
|
+
/>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- **Example (Horizontal Player with full metadata):**
|
|
238
|
+
```typescript
|
|
239
|
+
<VPPlayer
|
|
240
|
+
playerId="horizontal-player"
|
|
241
|
+
projectId="agmipnzb"
|
|
242
|
+
videoId="vjsnuhvm"
|
|
243
|
+
scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
|
|
244
|
+
apiKey="YOUR_API_KEY"
|
|
245
|
+
onVideoStarted={(videoData) => {
|
|
246
|
+
console.log('Video started:', videoData.title);
|
|
247
|
+
console.log('Author:', videoData.author);
|
|
248
|
+
console.log('Tags:', videoData.tags);
|
|
249
|
+
console.log('Published:', videoData.publishDate);
|
|
250
|
+
console.log('Premium:', videoData.premium);
|
|
251
|
+
|
|
252
|
+
// Send to analytics
|
|
253
|
+
analytics.track('video_started', {
|
|
254
|
+
video_id: videoData.videoId,
|
|
255
|
+
title: videoData.title,
|
|
256
|
+
author: videoData.author,
|
|
257
|
+
tags: videoData.tags
|
|
258
|
+
});
|
|
259
|
+
}}
|
|
260
|
+
/>
|
|
261
|
+
```
|
|
262
|
+
|
|
151
263
|
## Configuration
|
|
152
264
|
|
|
153
265
|
##### The player configuration is defined by the VPPlayerConfig interface, which is partially overridden by the config prop and dynamically built based on the input types.
|
|
@@ -298,6 +410,165 @@ const MyComponent = () => (
|
|
|
298
410
|
}
|
|
299
411
|
```
|
|
300
412
|
|
|
413
|
+
## Video Tracking & Analytics
|
|
414
|
+
|
|
415
|
+
The VPPlayer component provides two powerful callbacks for tracking video playback and playlist data:
|
|
416
|
+
|
|
417
|
+
### `onPlaylistData` - Playlist Data Callback
|
|
418
|
+
|
|
419
|
+
Fires once when playlist is loaded. Useful for building custom UI or pre-loading data.
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
import { VPPlayer } from "@dvxx/vp-player";
|
|
423
|
+
import { useState } from "react";
|
|
424
|
+
|
|
425
|
+
const MyPlaylistComponent = () => {
|
|
426
|
+
const [videos, setVideos] = useState([]);
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<>
|
|
430
|
+
{/* Display video list */}
|
|
431
|
+
<ul>
|
|
432
|
+
{videos.map((video, idx) => (
|
|
433
|
+
<li key={idx}>
|
|
434
|
+
{video.title} {video.isBackupPlaylist && "(Backup)"}
|
|
435
|
+
</li>
|
|
436
|
+
))}
|
|
437
|
+
</ul>
|
|
438
|
+
|
|
439
|
+
{/* Player with callback */}
|
|
440
|
+
<VPPlayer
|
|
441
|
+
playerId="my-playlist-player"
|
|
442
|
+
projectId="agmipnzb"
|
|
443
|
+
playlistId="lzxikgjw"
|
|
444
|
+
apiKey="YOUR_API_KEY"
|
|
445
|
+
onPlaylistData={(playlistVideos) => {
|
|
446
|
+
setVideos(playlistVideos);
|
|
447
|
+
console.log("Loaded videos:", playlistVideos.length);
|
|
448
|
+
}}
|
|
449
|
+
/>
|
|
450
|
+
</>
|
|
451
|
+
);
|
|
452
|
+
};
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### `onVideoStarted` - Video Change Tracking
|
|
456
|
+
|
|
457
|
+
Fires every time a video starts (scroll, click, auto-play). Perfect for analytics and real-time UI updates.
|
|
458
|
+
|
|
459
|
+
**Vertical Player Example:**
|
|
460
|
+
|
|
461
|
+
```typescript
|
|
462
|
+
<VPPlayer
|
|
463
|
+
playerId="reels-player"
|
|
464
|
+
projectId="agmipnzb"
|
|
465
|
+
playlistId="lzxikgjw"
|
|
466
|
+
scriptUrl="https://host.vpplayer.tech/vertical-player/rbqcdwznd.js"
|
|
467
|
+
isReels={true}
|
|
468
|
+
apiKey="YOUR_API_KEY"
|
|
469
|
+
onVideoStarted={(videoData) => {
|
|
470
|
+
// Fires on scroll or arrow navigation
|
|
471
|
+
console.log("Now playing:", videoData.title);
|
|
472
|
+
console.log("Video index:", videoData.videoIndex);
|
|
473
|
+
|
|
474
|
+
// Send to analytics
|
|
475
|
+
trackVideoView({
|
|
476
|
+
videoId: videoData.videoId,
|
|
477
|
+
index: videoData.videoIndex,
|
|
478
|
+
isBackup: videoData.isBackupPlaylist
|
|
479
|
+
});
|
|
480
|
+
}}
|
|
481
|
+
/>
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
**Horizontal Player Example (with full metadata):**
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
<VPPlayer
|
|
488
|
+
playerId="standard-player"
|
|
489
|
+
projectId="agmipnzb"
|
|
490
|
+
videoId="vjsnuhvm"
|
|
491
|
+
scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
|
|
492
|
+
apiKey="YOUR_API_KEY"
|
|
493
|
+
onVideoStarted={(videoData) => {
|
|
494
|
+
// Fires on next/previous or auto-play
|
|
495
|
+
// Full metadata fetched from API
|
|
496
|
+
console.log({
|
|
497
|
+
title: videoData.title,
|
|
498
|
+
author: videoData.author,
|
|
499
|
+
tags: videoData.tags,
|
|
500
|
+
publishDate: videoData.publishDate,
|
|
501
|
+
premium: videoData.premium,
|
|
502
|
+
description: videoData.description
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
// Rich analytics tracking
|
|
506
|
+
analytics.track("video_view", {
|
|
507
|
+
video_id: videoData.videoId,
|
|
508
|
+
video_title: videoData.title,
|
|
509
|
+
author: videoData.author,
|
|
510
|
+
tags: videoData.tags,
|
|
511
|
+
is_premium: videoData.premium,
|
|
512
|
+
project_id: videoData.projectId
|
|
513
|
+
});
|
|
514
|
+
}}
|
|
515
|
+
/>
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
**Combined Example (both callbacks):**
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
import { VPPlayer } from "@dvxx/vp-player";
|
|
522
|
+
import { useState } from "react";
|
|
523
|
+
|
|
524
|
+
const AdvancedPlayerComponent = () => {
|
|
525
|
+
const [playlistVideos, setPlaylistVideos] = useState([]);
|
|
526
|
+
const [currentVideo, setCurrentVideo] = useState(null);
|
|
527
|
+
|
|
528
|
+
return (
|
|
529
|
+
<div>
|
|
530
|
+
{/* Current video info */}
|
|
531
|
+
{currentVideo && (
|
|
532
|
+
<div className="video-info">
|
|
533
|
+
<h3>{currentVideo.title}</h3>
|
|
534
|
+
<p>Video {currentVideo.videoIndex + 1} of {playlistVideos.length}</p>
|
|
535
|
+
{currentVideo.author && <p>By: {currentVideo.author}</p>}
|
|
536
|
+
{currentVideo.tags && <p>Tags: {currentVideo.tags.join(", ")}</p>}
|
|
537
|
+
</div>
|
|
538
|
+
)}
|
|
539
|
+
|
|
540
|
+
{/* Player */}
|
|
541
|
+
<VPPlayer
|
|
542
|
+
playerId="advanced-player"
|
|
543
|
+
projectId="agmipnzb"
|
|
544
|
+
playlistId="lzxikgjw"
|
|
545
|
+
scriptUrl="https://host.vpplayer.tech/player/ptkzurnx.js"
|
|
546
|
+
apiKey="YOUR_API_KEY"
|
|
547
|
+
onPlaylistData={(videos) => {
|
|
548
|
+
setPlaylistVideos(videos);
|
|
549
|
+
console.log(`Playlist loaded: ${videos.length} videos`);
|
|
550
|
+
}}
|
|
551
|
+
onVideoStarted={(videoData) => {
|
|
552
|
+
setCurrentVideo(videoData);
|
|
553
|
+
console.log(`Playing video ${videoData.videoIndex + 1}`);
|
|
554
|
+
}}
|
|
555
|
+
/>
|
|
556
|
+
|
|
557
|
+
{/* Video playlist */}
|
|
558
|
+
<div className="playlist">
|
|
559
|
+
{playlistVideos.map((video, idx) => (
|
|
560
|
+
<div
|
|
561
|
+
key={idx}
|
|
562
|
+
className={currentVideo?.videoIndex === idx ? "active" : ""}
|
|
563
|
+
>
|
|
564
|
+
{video.title}
|
|
565
|
+
</div>
|
|
566
|
+
))}
|
|
567
|
+
</div>
|
|
568
|
+
</div>
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
```
|
|
301
572
|
<!-- Release notes WIP -->
|
|
302
573
|
<!-- v. 1.0.0 -->
|
|
303
574
|
<!-- Single video file, Playlist with files, Single Api video, Playlist Api-->
|