bitmovin-player-react-native 0.1.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/LICENSE +21 -0
- package/README.md +274 -0
- package/RNBitmovinPlayer.podspec +23 -0
- package/android/build.gradle +55 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt +279 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +264 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt +139 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt +33 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt +162 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/extensions/Events.kt +15 -0
- package/ios/Event+JSON.swift +132 -0
- package/ios/PlayerModule.m +61 -0
- package/ios/PlayerModule.swift +347 -0
- package/ios/RCTConvert+BitmovinPlayer.swift +79 -0
- package/ios/RNBitmovinPlayer.h +7 -0
- package/ios/RNBitmovinPlayer.xcodeproj/project.pbxproj +303 -0
- package/ios/RNPlayerView+PlayerListener.swift +83 -0
- package/ios/RNPlayerView.swift +50 -0
- package/ios/RNPlayerViewManager.m +29 -0
- package/ios/RNPlayerViewManager.swift +60 -0
- package/lib/index.d.ts +486 -0
- package/lib/index.js +218 -0
- package/lib/index.mjs +191 -0
- package/package.json +82 -0
- package/src/components/PlayerView/events.ts +69 -0
- package/src/components/PlayerView/index.tsx +106 -0
- package/src/components/PlayerView/native.ts +17 -0
- package/src/components/index.ts +1 -0
- package/src/events.ts +184 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/usePlayer.ts +10 -0
- package/src/hooks/useProxy.ts +36 -0
- package/src/index.ts +5 -0
- package/src/player.ts +229 -0
- package/src/source.ts +95 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Types of media that can be handled by the player.
|
|
5
|
+
*/
|
|
6
|
+
declare enum SourceType {
|
|
7
|
+
/**
|
|
8
|
+
* Indicates a missing source type.
|
|
9
|
+
*/
|
|
10
|
+
NONE = "none",
|
|
11
|
+
/**
|
|
12
|
+
* Indicates media type HLS.
|
|
13
|
+
*/
|
|
14
|
+
HLS = "hls",
|
|
15
|
+
/**
|
|
16
|
+
* Indicates media type DASH.
|
|
17
|
+
*/
|
|
18
|
+
DASH = "dash",
|
|
19
|
+
/**
|
|
20
|
+
* Indicates media type Progressive MP4.
|
|
21
|
+
*/
|
|
22
|
+
PROGRESSIVE = "progressive"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The different loading states a `Source` instance can be in.
|
|
26
|
+
*/
|
|
27
|
+
declare enum LoadingState {
|
|
28
|
+
/**
|
|
29
|
+
* The source is unloaded.
|
|
30
|
+
*/
|
|
31
|
+
UNLOADED = 0,
|
|
32
|
+
/**
|
|
33
|
+
* The source is currently loading.
|
|
34
|
+
*/
|
|
35
|
+
LOADING = 1,
|
|
36
|
+
/**
|
|
37
|
+
* The source is loaded.
|
|
38
|
+
*/
|
|
39
|
+
LOADED = 2
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Represents a source configuration that be loaded into a player instance.
|
|
43
|
+
*/
|
|
44
|
+
interface SourceConfig {
|
|
45
|
+
/**
|
|
46
|
+
* The url for this source configuration.
|
|
47
|
+
*/
|
|
48
|
+
url: string;
|
|
49
|
+
/**
|
|
50
|
+
* The `SourceType` for this configuration.
|
|
51
|
+
*/
|
|
52
|
+
type?: SourceType;
|
|
53
|
+
/**
|
|
54
|
+
* The title of the video source.
|
|
55
|
+
*/
|
|
56
|
+
title?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The URL to a preview image displayed until the video starts.
|
|
59
|
+
*/
|
|
60
|
+
poster?: string;
|
|
61
|
+
/**
|
|
62
|
+
* Indicates whether to show the poster image during playback.
|
|
63
|
+
* Useful, for example, for audio-only streams.
|
|
64
|
+
*/
|
|
65
|
+
isPosterPersistent?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Represents audio and video content that can be loaded into a player.
|
|
69
|
+
*/
|
|
70
|
+
interface Source {
|
|
71
|
+
/**
|
|
72
|
+
* The duration of the source in seconds if it’s a VoD or `INFINITY` if it’s a live stream.
|
|
73
|
+
* Default value is `0` if the duration is not available or not known.
|
|
74
|
+
*/
|
|
75
|
+
duration: number;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the source is currently active in a player (i.e. playing back or paused).
|
|
78
|
+
* Only one source can be active in the same player instance at any time.
|
|
79
|
+
*/
|
|
80
|
+
isActive: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Whether the source is currently attached to a player instance.
|
|
83
|
+
*/
|
|
84
|
+
isAttachedToPlayer: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Metadata for the currently loaded source.
|
|
87
|
+
* Setting the metadata value for a source is not supported yet.
|
|
88
|
+
*/
|
|
89
|
+
metadata?: Record<string, any>;
|
|
90
|
+
/**
|
|
91
|
+
* The current `LoadingState` of the source.
|
|
92
|
+
*/
|
|
93
|
+
loadingState?: LoadingState;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Object used to configure a new `Player` instance.
|
|
98
|
+
*/
|
|
99
|
+
interface PlayerConfig {
|
|
100
|
+
/**
|
|
101
|
+
* Optionally user-defined string `id` for the native `Player` instances. Used to access a certain native `Player` instance from any point in the source code then call methods/properties on it.
|
|
102
|
+
*
|
|
103
|
+
* When left empty, a random `UUIDv4` is generated for it.
|
|
104
|
+
* @example
|
|
105
|
+
* Accessing or creating the `Player` with `nativeId` equal to `my-player`:
|
|
106
|
+
* ```
|
|
107
|
+
* const player = new Player({ nativeId: 'my-player' })
|
|
108
|
+
* player.play(); // call methods and properties...
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
nativeId?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Bitmovin license key that can be found in the Bitmovin portal.
|
|
114
|
+
* If a license key is set here, it will be used instead of the license key found in the `Info.plist` and `AndroidManifest.xml`.
|
|
115
|
+
* @example
|
|
116
|
+
* Configuring the player license key from source code:
|
|
117
|
+
* ```
|
|
118
|
+
* const player = new Player({
|
|
119
|
+
* licenseKey: '\<LICENSE-KEY-CODE\>',
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
* @example
|
|
123
|
+
* `licenseKey` can be safely omitted from source code if it has
|
|
124
|
+
* been configured in Info.plist/AndroidManifest.xml.
|
|
125
|
+
* ```
|
|
126
|
+
* const player = new Player(); // omit `licenseKey`
|
|
127
|
+
* player.play(); // call methods and properties...
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
licenseKey?: string;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Loads, controls and renders audio and video content represented through `Source`s. A player
|
|
134
|
+
* instance can be created via the `usePlayer` hook and will idle until one or more `Source`s are
|
|
135
|
+
* loaded. Once `load` is called, the player becomes active and initiates necessary downloads to
|
|
136
|
+
* start playback of the loaded source(s).
|
|
137
|
+
*
|
|
138
|
+
* Can be attached to `PlayerView` component in order to use Bitmovin's Player Web UI.
|
|
139
|
+
* @see PlayerView
|
|
140
|
+
*/
|
|
141
|
+
declare class Player {
|
|
142
|
+
/**
|
|
143
|
+
* User-defined `nativeId` string or random `UUIDv4` identifying this `Player` in the native side.
|
|
144
|
+
*/
|
|
145
|
+
readonly nativeId: string;
|
|
146
|
+
/**
|
|
147
|
+
* Configuration object used to initialize this `Player`.
|
|
148
|
+
*/
|
|
149
|
+
readonly config: PlayerConfig | null;
|
|
150
|
+
constructor(config?: PlayerConfig);
|
|
151
|
+
/**
|
|
152
|
+
* Loads a new `Source` into the player.
|
|
153
|
+
*/
|
|
154
|
+
load: (source: SourceConfig) => void;
|
|
155
|
+
/**
|
|
156
|
+
* Unloads all `Source`s from the player.
|
|
157
|
+
*/
|
|
158
|
+
unload: () => void;
|
|
159
|
+
/**
|
|
160
|
+
* Starts or resumes playback after being paused. Has no effect if the player is already playing.
|
|
161
|
+
*/
|
|
162
|
+
play: () => void;
|
|
163
|
+
/**
|
|
164
|
+
* Pauses the video if it is playing. Has no effect if the player is already paused.
|
|
165
|
+
*/
|
|
166
|
+
pause: () => void;
|
|
167
|
+
/**
|
|
168
|
+
* Seeks to the given playback time specified by the parameter `time` in seconds. Must not be
|
|
169
|
+
* greater than the total duration of the video. Has no effect when watching a live stream since
|
|
170
|
+
* seeking is not possible.
|
|
171
|
+
*
|
|
172
|
+
* @param time - The time to seek to in seconds.
|
|
173
|
+
*/
|
|
174
|
+
seek: (time: number) => void;
|
|
175
|
+
/**
|
|
176
|
+
* Mutes the player if an audio track is available. Has no effect if the player is already muted.
|
|
177
|
+
*/
|
|
178
|
+
mute: () => void;
|
|
179
|
+
/**
|
|
180
|
+
* Unmutes the player if it is muted. Has no effect if the player is already unmuted.
|
|
181
|
+
*/
|
|
182
|
+
unmute: () => void;
|
|
183
|
+
/**
|
|
184
|
+
* Destroys the player and releases all of its allocated resources.
|
|
185
|
+
* The player instance must not be used after calling this method.
|
|
186
|
+
*/
|
|
187
|
+
destroy: () => void;
|
|
188
|
+
/**
|
|
189
|
+
* Sets the player's volume between 0 (silent) and 100 (max volume).
|
|
190
|
+
*
|
|
191
|
+
* @param volume - The volume level to set.
|
|
192
|
+
*/
|
|
193
|
+
setVolume: (volume: number) => void;
|
|
194
|
+
/**
|
|
195
|
+
* @returns The currently active source or null if no source is active.
|
|
196
|
+
*/
|
|
197
|
+
getSource: () => Promise<Source>;
|
|
198
|
+
/**
|
|
199
|
+
* @returns The player's current volume level.
|
|
200
|
+
*/
|
|
201
|
+
getVolume: () => Promise<number>;
|
|
202
|
+
/**
|
|
203
|
+
* @returns The current playback time in seconds.
|
|
204
|
+
*
|
|
205
|
+
* For VoD streams the returned time ranges between 0 and the duration of the asset.
|
|
206
|
+
*
|
|
207
|
+
* For live streams it can be specified if an absolute UNIX timestamp or a value
|
|
208
|
+
* relative to the playback start should be returned.
|
|
209
|
+
*
|
|
210
|
+
* @param mode - The time mode to specify: an absolute UNIX timestamp ('absolute') or relative time ('relative').
|
|
211
|
+
*/
|
|
212
|
+
getCurrentTime: (mode?: "relative" | "absolute" | undefined) => Promise<number>;
|
|
213
|
+
/**
|
|
214
|
+
* @returns The total duration in seconds of the current video or INFINITY if it’s a live stream.
|
|
215
|
+
*/
|
|
216
|
+
getDuration: () => Promise<number>;
|
|
217
|
+
/**
|
|
218
|
+
* @returns `true` if the player is muted.
|
|
219
|
+
*/
|
|
220
|
+
isMuted: () => Promise<boolean>;
|
|
221
|
+
/**
|
|
222
|
+
* @returns `true` if the player is currently playing, i.e. has started and is not paused.
|
|
223
|
+
*/
|
|
224
|
+
isPlaying: () => Promise<boolean>;
|
|
225
|
+
/**
|
|
226
|
+
* @returns `true` if the player has started playback but it's currently paused.
|
|
227
|
+
*/
|
|
228
|
+
isPaused: () => Promise<boolean>;
|
|
229
|
+
/**
|
|
230
|
+
* @returns `true` if the displayed video is a live stream.
|
|
231
|
+
*/
|
|
232
|
+
isLive: () => Promise<boolean>;
|
|
233
|
+
/**
|
|
234
|
+
* @remarks Only available for iOS devices.
|
|
235
|
+
* @returns `true` when media is played externally using AirPlay.
|
|
236
|
+
*/
|
|
237
|
+
isAirPlayActive: () => Promise<boolean>;
|
|
238
|
+
/**
|
|
239
|
+
* @remarks Only available for iOS devices.
|
|
240
|
+
* @returns `true` when AirPlay is available.
|
|
241
|
+
*/
|
|
242
|
+
isAirPlayAvailable: () => Promise<boolean>;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Base event type for all events.
|
|
247
|
+
*/
|
|
248
|
+
interface Event {
|
|
249
|
+
/**
|
|
250
|
+
* This event name as it is on the native side.
|
|
251
|
+
*/
|
|
252
|
+
name: string;
|
|
253
|
+
/**
|
|
254
|
+
* The UNIX timestamp in which this event happened.
|
|
255
|
+
*/
|
|
256
|
+
timestamp: number;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Base event type for error and warning events.
|
|
260
|
+
*/
|
|
261
|
+
interface ErrorEvent extends Event {
|
|
262
|
+
/**
|
|
263
|
+
* Error/Warning's code number.
|
|
264
|
+
*/
|
|
265
|
+
code?: number;
|
|
266
|
+
/**
|
|
267
|
+
* Error/Warning's localized message.
|
|
268
|
+
*/
|
|
269
|
+
message: string;
|
|
270
|
+
/**
|
|
271
|
+
* Underlying data emitted with the Error/Warning.
|
|
272
|
+
*/
|
|
273
|
+
data?: Record<string, any>;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Emitted when a source is loaded into the player.
|
|
277
|
+
* Seeking and time shifting are allowed as soon as this event is seen.
|
|
278
|
+
*/
|
|
279
|
+
interface PlayerActiveEvent extends Event {
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Emitted when a player error happens.
|
|
283
|
+
*/
|
|
284
|
+
interface PlayerErrorEvent extends ErrorEvent {
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Emitted when a player warning happens.
|
|
288
|
+
*/
|
|
289
|
+
interface PlayerWarningEvent extends ErrorEvent {
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Emitted when the player is destroyed.
|
|
293
|
+
*/
|
|
294
|
+
interface DestroyEvent extends Event {
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Emitted when the player is muted.
|
|
298
|
+
*/
|
|
299
|
+
interface MutedEvent extends Event {
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Emitted when the player is unmuted.
|
|
303
|
+
*/
|
|
304
|
+
interface UnmutedEvent extends Event {
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Emitted when the player is ready for immediate playback, because initial audio/video
|
|
308
|
+
* has been downloaded.
|
|
309
|
+
*/
|
|
310
|
+
interface ReadyEvent extends Event {
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Emitted when the player is paused.
|
|
314
|
+
*/
|
|
315
|
+
interface PausedEvent extends Event {
|
|
316
|
+
/**
|
|
317
|
+
* The player's playback time from when this event happened.
|
|
318
|
+
*/
|
|
319
|
+
time: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Emitted when the player received an intention to start/resume playback.
|
|
323
|
+
*/
|
|
324
|
+
interface PlayEvent extends Event {
|
|
325
|
+
/**
|
|
326
|
+
* The player's playback time from when this event happened.
|
|
327
|
+
*/
|
|
328
|
+
time: number;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Emitted when playback has started.
|
|
332
|
+
*/
|
|
333
|
+
interface PlayingEvent extends Event {
|
|
334
|
+
/**
|
|
335
|
+
* The player's playback time from when this event happened.
|
|
336
|
+
*/
|
|
337
|
+
time: number;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Emitted when the playback of the current media has finished.
|
|
341
|
+
*/
|
|
342
|
+
interface PlaybackFinishedEvent extends Event {
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Emitted when the player is about to seek to a new position.
|
|
346
|
+
* Only applies to VoD streams.
|
|
347
|
+
*/
|
|
348
|
+
interface SeekEvent extends Event {
|
|
349
|
+
/**
|
|
350
|
+
* Removed source metadata.
|
|
351
|
+
*/
|
|
352
|
+
from: {
|
|
353
|
+
time: number;
|
|
354
|
+
source: Source;
|
|
355
|
+
};
|
|
356
|
+
/**
|
|
357
|
+
* Added source metadata.
|
|
358
|
+
*/
|
|
359
|
+
to: {
|
|
360
|
+
time: number;
|
|
361
|
+
source: Source;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Emitted when seeking has finished and data to continue playback is available.
|
|
366
|
+
* Only applies to VoD streams.
|
|
367
|
+
*/
|
|
368
|
+
interface SeekedEvent extends Event {
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Emitted when the current playback time has changed.
|
|
372
|
+
*/
|
|
373
|
+
interface TimeChangedEvent extends Event {
|
|
374
|
+
/**
|
|
375
|
+
* The player's playback time from when this event happened.
|
|
376
|
+
*/
|
|
377
|
+
currentTime: number;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Emitted when a new source loading has started.
|
|
381
|
+
* It doesn't mean that the loading of the new manifest has finished.
|
|
382
|
+
*/
|
|
383
|
+
interface SourceLoadEvent extends Event {
|
|
384
|
+
/**
|
|
385
|
+
* Source that is about to load.
|
|
386
|
+
*/
|
|
387
|
+
source: Source;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Emitted when a new source is loaded.
|
|
391
|
+
* It doesn't mean that the loading of the new manifest has finished.
|
|
392
|
+
*/
|
|
393
|
+
interface SourceLoadedEvent extends Event {
|
|
394
|
+
/**
|
|
395
|
+
* Source that was loaded into player.
|
|
396
|
+
*/
|
|
397
|
+
source: Source;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Emitted when the current source has been unloaded.
|
|
401
|
+
*/
|
|
402
|
+
interface SourceUnloadedEvent extends Event {
|
|
403
|
+
/**
|
|
404
|
+
* Source that was unloaded from player.
|
|
405
|
+
*/
|
|
406
|
+
source: Source;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Emitted when a source error happens.
|
|
410
|
+
*/
|
|
411
|
+
interface SourceErrorEvent extends ErrorEvent {
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Emitted when a source warning happens.
|
|
415
|
+
*/
|
|
416
|
+
interface SourceWarningEvent extends ErrorEvent {
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* React hook that creates and returns a reference to a `Player` instance
|
|
421
|
+
* that can be used inside any component.
|
|
422
|
+
*/
|
|
423
|
+
declare function usePlayer(config?: PlayerConfig): Player;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Type that defines all event props supported by `PlayerView` and `NativePlayerView`.
|
|
427
|
+
* Used to generate the specific events interface for each component.
|
|
428
|
+
*/
|
|
429
|
+
interface EventProps {
|
|
430
|
+
onEvent: Event;
|
|
431
|
+
onPlayerActive: PlayerActiveEvent;
|
|
432
|
+
onPlayerError: PlayerErrorEvent;
|
|
433
|
+
onPlayerWarning: PlayerWarningEvent;
|
|
434
|
+
onDestroy: DestroyEvent;
|
|
435
|
+
onMuted: MutedEvent;
|
|
436
|
+
onUnmuted: UnmutedEvent;
|
|
437
|
+
onReady: ReadyEvent;
|
|
438
|
+
onPaused: PausedEvent;
|
|
439
|
+
onPlay: PlayEvent;
|
|
440
|
+
onPlaying: PlayingEvent;
|
|
441
|
+
onPlaybackFinished: PlaybackFinishedEvent;
|
|
442
|
+
onSeek: SeekEvent;
|
|
443
|
+
onSeeked: SeekedEvent;
|
|
444
|
+
onTimeChanged: TimeChangedEvent;
|
|
445
|
+
onSourceLoad: SourceLoadEvent;
|
|
446
|
+
onSourceLoaded: SourceLoadedEvent;
|
|
447
|
+
onSourceUnloaded: SourceUnloadedEvent;
|
|
448
|
+
onSourceError: SourceErrorEvent;
|
|
449
|
+
onSourceWarning: SourceWarningEvent;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Event props for `PlayerView`.
|
|
453
|
+
*
|
|
454
|
+
* Note the events of `PlayerView` are simply a proxy over
|
|
455
|
+
* the events from `NativePlayerView` just removing RN's bubbling data.
|
|
456
|
+
*/
|
|
457
|
+
declare type PlayerViewEvents = {
|
|
458
|
+
[Prop in keyof EventProps]?: (event: EventProps[Prop]) => void;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Base `PlayerView` component props. Used to stablish common
|
|
463
|
+
* props between `NativePlayerView` and `PlayerView`.
|
|
464
|
+
* @see NativePlayerView
|
|
465
|
+
*/
|
|
466
|
+
interface BasePlayerViewProps {
|
|
467
|
+
style?: ViewStyle;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* `PlayerView` component props.
|
|
471
|
+
* @see PlayerView
|
|
472
|
+
*/
|
|
473
|
+
interface PlayerViewProps extends BasePlayerViewProps, PlayerViewEvents {
|
|
474
|
+
/**
|
|
475
|
+
* `Player` instance (generally returned from `usePlayer` hook) that will control
|
|
476
|
+
* and render audio/video inside the `PlayerView`.
|
|
477
|
+
*/
|
|
478
|
+
player: Player;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Component that provides the Bitmovin Player UI and default UI handling to an attached `Player` instance.
|
|
482
|
+
* This component needs a `Player` instance to work properly so make sure one is passed to it as a prop.
|
|
483
|
+
*/
|
|
484
|
+
declare function PlayerView(props: PlayerViewProps): JSX.Element;
|
|
485
|
+
|
|
486
|
+
export { BasePlayerViewProps, DestroyEvent, ErrorEvent, Event, LoadingState, MutedEvent, PausedEvent, PlayEvent, PlaybackFinishedEvent, Player, PlayerActiveEvent, PlayerConfig, PlayerErrorEvent, PlayerView, PlayerViewProps, PlayerWarningEvent, PlayingEvent, ReadyEvent, SeekEvent, SeekedEvent, Source, SourceConfig, SourceErrorEvent, SourceLoadEvent, SourceLoadedEvent, SourceType, SourceUnloadedEvent, SourceWarningEvent, TimeChangedEvent, UnmutedEvent, usePlayer };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var __publicField = (obj, key, value) => {
|
|
24
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
LoadingState: () => LoadingState,
|
|
32
|
+
Player: () => Player,
|
|
33
|
+
PlayerView: () => PlayerView,
|
|
34
|
+
SourceType: () => SourceType,
|
|
35
|
+
usePlayer: () => usePlayer
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
|
|
39
|
+
// src/player.ts
|
|
40
|
+
var import_react_native = require("react-native");
|
|
41
|
+
var PlayerModule = import_react_native.NativeModules.PlayerModule;
|
|
42
|
+
var Player = class {
|
|
43
|
+
constructor(config) {
|
|
44
|
+
__publicField(this, "nativeId");
|
|
45
|
+
__publicField(this, "config");
|
|
46
|
+
__publicField(this, "load", (source) => {
|
|
47
|
+
PlayerModule.loadSource(this.nativeId, source);
|
|
48
|
+
});
|
|
49
|
+
__publicField(this, "unload", () => {
|
|
50
|
+
PlayerModule.unload(this.nativeId);
|
|
51
|
+
});
|
|
52
|
+
__publicField(this, "play", () => {
|
|
53
|
+
PlayerModule.play(this.nativeId);
|
|
54
|
+
});
|
|
55
|
+
__publicField(this, "pause", () => {
|
|
56
|
+
PlayerModule.pause(this.nativeId);
|
|
57
|
+
});
|
|
58
|
+
__publicField(this, "seek", (time) => {
|
|
59
|
+
PlayerModule.seek(this.nativeId, time);
|
|
60
|
+
});
|
|
61
|
+
__publicField(this, "mute", () => {
|
|
62
|
+
PlayerModule.mute(this.nativeId);
|
|
63
|
+
});
|
|
64
|
+
__publicField(this, "unmute", () => {
|
|
65
|
+
PlayerModule.unmute(this.nativeId);
|
|
66
|
+
});
|
|
67
|
+
__publicField(this, "destroy", () => {
|
|
68
|
+
PlayerModule.destroy(this.nativeId);
|
|
69
|
+
});
|
|
70
|
+
__publicField(this, "setVolume", (volume) => {
|
|
71
|
+
PlayerModule.setVolume(this.nativeId, volume);
|
|
72
|
+
});
|
|
73
|
+
__publicField(this, "getSource", async () => {
|
|
74
|
+
return PlayerModule.source(this.nativeId);
|
|
75
|
+
});
|
|
76
|
+
__publicField(this, "getVolume", async () => {
|
|
77
|
+
return PlayerModule.getVolume(this.nativeId);
|
|
78
|
+
});
|
|
79
|
+
__publicField(this, "getCurrentTime", async (mode) => {
|
|
80
|
+
return PlayerModule.currentTime(this.nativeId, mode);
|
|
81
|
+
});
|
|
82
|
+
__publicField(this, "getDuration", async () => {
|
|
83
|
+
return PlayerModule.duration(this.nativeId);
|
|
84
|
+
});
|
|
85
|
+
__publicField(this, "isMuted", async () => {
|
|
86
|
+
return PlayerModule.isMuted(this.nativeId);
|
|
87
|
+
});
|
|
88
|
+
__publicField(this, "isPlaying", async () => {
|
|
89
|
+
return PlayerModule.isPlaying(this.nativeId);
|
|
90
|
+
});
|
|
91
|
+
__publicField(this, "isPaused", async () => {
|
|
92
|
+
return PlayerModule.isPaused(this.nativeId);
|
|
93
|
+
});
|
|
94
|
+
__publicField(this, "isLive", async () => {
|
|
95
|
+
return PlayerModule.isLive(this.nativeId);
|
|
96
|
+
});
|
|
97
|
+
__publicField(this, "isAirPlayActive", async () => {
|
|
98
|
+
if (import_react_native.Platform.OS === "android") {
|
|
99
|
+
console.warn(`[Player ${this.nativeId}] Method isAirPlayActive is not available for Android. Only iOS devices.`);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return PlayerModule.isAirPlayActive(this.nativeId);
|
|
103
|
+
});
|
|
104
|
+
__publicField(this, "isAirPlayAvailable", async () => {
|
|
105
|
+
if (import_react_native.Platform.OS === "android") {
|
|
106
|
+
console.warn(`[Player ${this.nativeId}] Method isAirPlayAvailable is not available for Android. Only iOS devices.`);
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return PlayerModule.isAirPlayAvailable(this.nativeId);
|
|
110
|
+
});
|
|
111
|
+
this.config = config ?? null;
|
|
112
|
+
this.nativeId = config?.nativeId ?? PlayerModule.generateUUIDv4();
|
|
113
|
+
PlayerModule.initWithConfig(this.nativeId, this.config);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/source.ts
|
|
118
|
+
var SourceType = /* @__PURE__ */ ((SourceType2) => {
|
|
119
|
+
SourceType2["NONE"] = "none";
|
|
120
|
+
SourceType2["HLS"] = "hls";
|
|
121
|
+
SourceType2["DASH"] = "dash";
|
|
122
|
+
SourceType2["PROGRESSIVE"] = "progressive";
|
|
123
|
+
return SourceType2;
|
|
124
|
+
})(SourceType || {});
|
|
125
|
+
var LoadingState = /* @__PURE__ */ ((LoadingState2) => {
|
|
126
|
+
LoadingState2[LoadingState2["UNLOADED"] = 0] = "UNLOADED";
|
|
127
|
+
LoadingState2[LoadingState2["LOADING"] = 1] = "LOADING";
|
|
128
|
+
LoadingState2[LoadingState2["LOADED"] = 2] = "LOADED";
|
|
129
|
+
return LoadingState2;
|
|
130
|
+
})(LoadingState || {});
|
|
131
|
+
|
|
132
|
+
// src/hooks/usePlayer.ts
|
|
133
|
+
var import_react = require("react");
|
|
134
|
+
function usePlayer(config) {
|
|
135
|
+
return (0, import_react.useRef)(new Player(config)).current;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/components/PlayerView/index.tsx
|
|
139
|
+
var import_react3 = __toESM(require("react"));
|
|
140
|
+
var import_react_native4 = require("react-native");
|
|
141
|
+
|
|
142
|
+
// src/components/PlayerView/native.ts
|
|
143
|
+
var import_react_native2 = require("react-native");
|
|
144
|
+
var NativePlayerView = (0, import_react_native2.requireNativeComponent)("NativePlayerView");
|
|
145
|
+
|
|
146
|
+
// src/hooks/useProxy.ts
|
|
147
|
+
var import_lodash = __toESM(require("lodash.omit"));
|
|
148
|
+
var import_react2 = require("react");
|
|
149
|
+
var import_react_native3 = require("react-native");
|
|
150
|
+
function unwrapNativeEvent(event) {
|
|
151
|
+
return (0, import_lodash.default)(event.nativeEvent, ["target"]);
|
|
152
|
+
}
|
|
153
|
+
function useProxy(viewRef, proxy) {
|
|
154
|
+
const proxyRef = (0, import_react2.useRef)(proxy);
|
|
155
|
+
return (0, import_react2.useCallback)((event) => {
|
|
156
|
+
const node = event.target._nativeTag;
|
|
157
|
+
if (node === (0, import_react_native3.findNodeHandle)(viewRef.current)) {
|
|
158
|
+
proxyRef.current?.(unwrapNativeEvent(event));
|
|
159
|
+
}
|
|
160
|
+
}, [viewRef]);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/components/PlayerView/index.tsx
|
|
164
|
+
var styles = import_react_native4.StyleSheet.create({
|
|
165
|
+
baseStyle: {
|
|
166
|
+
alignSelf: "stretch"
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
function dispatch(command, node, playerId) {
|
|
170
|
+
const commandId = import_react_native4.Platform.OS === "android" ? import_react_native4.UIManager.NativePlayerView.Commands[command].toString() : import_react_native4.UIManager.getViewManagerConfig("NativePlayerView").Commands[command];
|
|
171
|
+
import_react_native4.UIManager.dispatchViewManagerCommand(node, commandId, import_react_native4.Platform.select({
|
|
172
|
+
ios: [playerId],
|
|
173
|
+
android: [node, playerId]
|
|
174
|
+
}));
|
|
175
|
+
}
|
|
176
|
+
function PlayerView(props) {
|
|
177
|
+
const nativeView = (0, import_react3.useRef)(null);
|
|
178
|
+
const style = import_react_native4.StyleSheet.flatten([styles.baseStyle, props.style]);
|
|
179
|
+
(0, import_react3.useEffect)(() => {
|
|
180
|
+
const node = (0, import_react_native4.findNodeHandle)(nativeView.current);
|
|
181
|
+
dispatch("attachPlayer", node, props.player.nativeId);
|
|
182
|
+
return () => {
|
|
183
|
+
dispatch("detachPlayer", node, props.player.nativeId);
|
|
184
|
+
};
|
|
185
|
+
}, [props.player.nativeId]);
|
|
186
|
+
return /* @__PURE__ */ import_react3.default.createElement(NativePlayerView, {
|
|
187
|
+
ref: nativeView,
|
|
188
|
+
style,
|
|
189
|
+
onEvent: useProxy(nativeView, props.onEvent),
|
|
190
|
+
onPlayerActive: useProxy(nativeView, props.onPlayerActive),
|
|
191
|
+
onPlayerError: useProxy(nativeView, props.onPlayerError),
|
|
192
|
+
onPlayerWarning: useProxy(nativeView, props.onPlayerWarning),
|
|
193
|
+
onDestroy: useProxy(nativeView, props.onDestroy),
|
|
194
|
+
onMuted: useProxy(nativeView, props.onMuted),
|
|
195
|
+
onUnmuted: useProxy(nativeView, props.onUnmuted),
|
|
196
|
+
onReady: useProxy(nativeView, props.onReady),
|
|
197
|
+
onPaused: useProxy(nativeView, props.onPaused),
|
|
198
|
+
onPlay: useProxy(nativeView, props.onPlay),
|
|
199
|
+
onPlaying: useProxy(nativeView, props.onPlaying),
|
|
200
|
+
onPlaybackFinished: useProxy(nativeView, props.onPlaybackFinished),
|
|
201
|
+
onSeek: useProxy(nativeView, props.onSeek),
|
|
202
|
+
onSeeked: useProxy(nativeView, props.onSeeked),
|
|
203
|
+
onTimeChanged: useProxy(nativeView, props.onTimeChanged),
|
|
204
|
+
onSourceLoad: useProxy(nativeView, props.onSourceLoad),
|
|
205
|
+
onSourceLoaded: useProxy(nativeView, props.onSourceLoaded),
|
|
206
|
+
onSourceUnloaded: useProxy(nativeView, props.onSourceUnloaded),
|
|
207
|
+
onSourceError: useProxy(nativeView, props.onSourceError),
|
|
208
|
+
onSourceWarning: useProxy(nativeView, props.onSourceWarning)
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
212
|
+
0 && (module.exports = {
|
|
213
|
+
LoadingState,
|
|
214
|
+
Player,
|
|
215
|
+
PlayerView,
|
|
216
|
+
SourceType,
|
|
217
|
+
usePlayer
|
|
218
|
+
});
|