@rajeev02/media 0.1.0 → 0.2.0
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 +154 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @rajeev02/media
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@rajeev02/media)
|
|
4
|
+
[](https://github.com/Rajeev02/rajeev-sdk/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
**Unified media player & download manager** with adaptive streaming (HLS/DASH), Picture-in-Picture, Chromecast/AirPlay, DRM (Widevine/FairPlay), quality selection, and offline downloads.
|
|
7
|
+
|
|
8
|
+
Part of [Rajeev SDK](https://github.com/Rajeev02/rajeev-sdk) — cross-platform infrastructure libraries for building apps that work everywhere.
|
|
9
|
+
|
|
10
|
+
## Why use this?
|
|
11
|
+
|
|
12
|
+
- **Adaptive streaming** — HLS & DASH with automatic quality switching based on bandwidth
|
|
13
|
+
- **DRM support** — Widevine (Android/Web) and FairPlay (iOS) for premium content protection
|
|
14
|
+
- **Picture-in-Picture** — Floating video player while using other apps
|
|
15
|
+
- **Casting** — Chromecast and AirPlay integration with unified API
|
|
16
|
+
- **Offline downloads** — Background download with pause/resume, progress tracking, storage limits
|
|
17
|
+
- **Resume playback** — Automatic resume from last position across sessions
|
|
18
|
+
- **Playback speed** — 0.5x to 3x speed with pitch correction
|
|
19
|
+
|
|
20
|
+
## Platform Support
|
|
21
|
+
|
|
22
|
+
| Platform | Engine | Status |
|
|
23
|
+
| ---------- | ---------- | ------ |
|
|
24
|
+
| iOS 16+ | TypeScript | ✅ |
|
|
25
|
+
| Android 7+ | TypeScript | ✅ |
|
|
26
|
+
| Web | TypeScript | ✅ |
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @rajeev02/media
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Peer Dependencies
|
|
35
|
+
|
|
36
|
+
- `react` >= 18.3.0
|
|
37
|
+
- `react-native` >= 0.84.0 _(optional)_
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
### Media Player
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { MediaPlayerController } from "@rajeev02/media";
|
|
45
|
+
|
|
46
|
+
const player = new MediaPlayerController({
|
|
47
|
+
autoPlay: true,
|
|
48
|
+
enablePiP: true,
|
|
49
|
+
enableCast: true,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Load a video with DRM
|
|
53
|
+
player.load({
|
|
54
|
+
uri: "https://stream.example.com/video.m3u8",
|
|
55
|
+
type: "video",
|
|
56
|
+
title: "My Movie",
|
|
57
|
+
drm: {
|
|
58
|
+
type: "widevine",
|
|
59
|
+
licenseServerUrl: "https://drm.example.com/license",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Listen for events
|
|
64
|
+
player.on((event) => {
|
|
65
|
+
switch (event.type) {
|
|
66
|
+
case "progress":
|
|
67
|
+
updateSeekbar(event.currentTimeMs);
|
|
68
|
+
break;
|
|
69
|
+
case "quality_changed":
|
|
70
|
+
showBadge(event.quality);
|
|
71
|
+
break;
|
|
72
|
+
case "buffering":
|
|
73
|
+
showSpinner(event.isBuffering);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Playback controls
|
|
79
|
+
player.play();
|
|
80
|
+
player.pause();
|
|
81
|
+
player.seek(60_000); // Seek to 1 minute
|
|
82
|
+
player.setRate(1.5); // 1.5x speed
|
|
83
|
+
player.setQuality("720p"); // Manual quality selection
|
|
84
|
+
player.enterPiP(); // Picture-in-Picture
|
|
85
|
+
player.skipForward(10_000); // Skip 10 seconds
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Offline Downloads
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { DownloadManager } from "@rajeev02/media";
|
|
92
|
+
|
|
93
|
+
const dm = new DownloadManager(
|
|
94
|
+
2, // Max concurrent downloads
|
|
95
|
+
2 * 1024 ** 3, // 2 GB storage limit
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
// Enqueue download
|
|
99
|
+
dm.enqueue({
|
|
100
|
+
id: "movie-001",
|
|
101
|
+
uri: "https://cdn.example.com/movie.mp4",
|
|
102
|
+
title: "Offline Movie",
|
|
103
|
+
estimatedSizeBytes: 500_000_000, // 500 MB
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Track progress
|
|
107
|
+
dm.onProgress((progress) => {
|
|
108
|
+
console.log(`${progress.percentComplete}% at ${progress.speedBps} B/s`);
|
|
109
|
+
console.log(`ETA: ${progress.estimatedTimeRemainingMs}ms`);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Manage downloads
|
|
113
|
+
dm.pause("movie-001");
|
|
114
|
+
dm.resume("movie-001");
|
|
115
|
+
dm.cancel("movie-001");
|
|
116
|
+
const all = dm.getAll(); // List all downloads with status
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## API Reference
|
|
120
|
+
|
|
121
|
+
### `MediaPlayerController`
|
|
122
|
+
|
|
123
|
+
| Method | Description |
|
|
124
|
+
| -------------------------------------- | ---------------------------- |
|
|
125
|
+
| `load(source)` | Load media source |
|
|
126
|
+
| `play()` / `pause()` | Play or pause |
|
|
127
|
+
| `seek(positionMs)` | Seek to position |
|
|
128
|
+
| `setRate(rate)` | Set playback speed (0.5–3.0) |
|
|
129
|
+
| `setQuality(quality)` | Set video quality |
|
|
130
|
+
| `setVolume(volume)` | Set volume (0–1) |
|
|
131
|
+
| `enterPiP()` / `exitPiP()` | Toggle Picture-in-Picture |
|
|
132
|
+
| `skipForward(ms)` / `skipBackward(ms)` | Skip forward/backward |
|
|
133
|
+
| `on(callback)` | Subscribe to player events |
|
|
134
|
+
| `destroy()` | Release player resources |
|
|
135
|
+
|
|
136
|
+
### `DownloadManager`
|
|
137
|
+
|
|
138
|
+
| Method | Description |
|
|
139
|
+
| -------------------------- | ----------------------- |
|
|
140
|
+
| `enqueue(config)` | Start a download |
|
|
141
|
+
| `pause(id)` / `resume(id)` | Pause or resume |
|
|
142
|
+
| `cancel(id)` | Cancel and delete |
|
|
143
|
+
| `getAll()` | List all downloads |
|
|
144
|
+
| `getById(id)` | Get download status |
|
|
145
|
+
| `onProgress(callback)` | Track download progress |
|
|
146
|
+
| `getTotalStorageUsed()` | Get total bytes used |
|
|
147
|
+
|
|
148
|
+
## Full Documentation
|
|
149
|
+
|
|
150
|
+
📖 [Complete API docs with casting, DRM, and playlist support](https://github.com/Rajeev02/rajeev-sdk/blob/main/docs/usage/MEDIA.md)
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT © 2026 [Rajeev Kumar Joshi](https://rajeev02.github.io)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rajeev02/media",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Unified Media Player Engine — adaptive streaming, PiP, offline download, DRM, Hotstar/Netflix style",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Rajeev Kumar Joshi <rajeevjoshi91@gmail.com> (https://rajeev02.github.io)",
|