react-native-unified-player 0.2.3 → 0.2.4

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.
Files changed (2) hide show
  1. package/README.md +85 -102
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,135 +1,118 @@
1
- # React Native Your Unified Player
1
+ # react-native-unified-player
2
2
 
3
- A powerful React Native component that provides a unified interface for playing both MP4 videos and WebRTC streams. Built with Fabric and the new React Native architecture.
3
+ Unified Player
4
+
5
+ A React Native component for playing videos via URL, built with Fabric.
4
6
 
5
7
  ## Features
6
8
 
7
- - 🎥 Support for MP4 video playback
8
- - 🌐 WebRTC streaming capabilities
9
- - 🔄 Unified interface for both video types
9
+ - 🎥 Play videos from a URL source
10
10
  - 📱 Native performance with Fabric architecture
11
- - 🎛️ Comprehensive playback controls
12
- - 📊 Event handling for player states
13
- - 🔍 Support for different resize modes
14
- - 🎚️ Volume and mute controls
15
- - ⏯️ Play/pause functionality
11
+ - 📊 Event handling for player states (Ready, Error, Progress, Complete, Stalled, Resumed)
12
+ - 🎛️ Control playback with methods (Play, Pause, Seek, Get Current Time, Get Duration)
13
+ - 🔄 Optional autoplay and loop
16
14
 
17
15
  ## Installation
18
16
 
19
17
  ```bash
20
- yarn add react-native-your-unified-player
18
+ yarn add react-native-unified-player
21
19
  ```
22
20
 
23
21
  or
24
22
 
25
23
  ```bash
26
- npm install react-native-your-unified-player
24
+ npm install react-native-unified-player
27
25
  ```
28
26
 
29
27
  ## Usage
30
28
 
31
29
  ### Basic Usage
32
30
 
33
- ```jsx
34
- import { YourUnifiedPlayerView } from 'react-native-your-unified-player';
35
-
36
- // For MP4 video
37
- <YourUnifiedPlayerView
38
- source={{
39
- type: 'url',
40
- uri: 'https://example.com/video.mp4'
41
- }}
42
- style={{ width: '100%', height: 300 }}
43
- paused={false}
44
- muted={false}
45
- volume={1.0}
46
- resizeMode="contain"
47
- onUrlLoad={({ duration, naturalSize }) => {
48
- console.log('Video loaded:', duration, naturalSize);
49
- }}
50
- onError={({ error, code }) => {
51
- console.error('Player error:', error, code);
52
- }}
53
- />
54
-
55
- // For WebRTC stream
56
- <YourUnifiedPlayerView
57
- source={{
58
- type: 'webrtc',
59
- signalingUrl: 'wss://example.com/signaling',
60
- iceServers: [
61
- { urls: 'stun:stun.l.google.com:19302' }
62
- ]
63
- }}
64
- style={{ width: '100%', height: 300 }}
65
- onWebRTCConnected={({ connectionInfo }) => {
66
- console.log('WebRTC connected:', connectionInfo);
67
- }}
68
- onWebRTCDisconnected={({ code, reason }) => {
69
- console.log('WebRTC disconnected:', code, reason);
70
- }}
71
- />
72
- ```
73
-
74
- ### Props
75
-
76
- #### Common Props
77
-
78
- | Prop | Type | Default | Description |
79
- |------|------|---------|-------------|
80
- | `paused` | `boolean` | `false` | Controls playback state |
81
- | `muted` | `boolean` | `false` | Controls audio mute state |
82
- | `volume` | `number` | `1.0` | Controls audio volume (0.0 to 1.0) |
83
- | `resizeMode` | `'contain' \| 'cover' \| 'stretch'` | `'contain'` | Controls how the video fits in the view |
84
-
85
- #### Source Props
86
-
87
- For MP4 videos:
88
- ```typescript
89
- {
90
- type: 'url';
91
- uri: string;
92
- }
93
- ```
94
-
95
- For WebRTC streams:
96
31
  ```typescript
97
- {
98
- type: 'webrtc';
99
- signalingUrl: string;
100
- streamConfig?: object;
101
- iceServers?: ReadonlyArray<{ urls: string | ReadonlyArray<string> }>;
102
- }
103
- }
32
+ import { UnifiedPlayerView, UnifiedPlayer, UnifiedPlayerEventTypes, UnifiedPlayerEvents } from 'react-native-unified-player';
33
+ import React, { useRef, useEffect } from 'react';
34
+ import { View } from 'react-native';
35
+
36
+ const MyPlayerComponent = () => {
37
+ const playerRef = useRef(null);
38
+
39
+ // Example of using event listeners (optional)
40
+ useEffect(() => {
41
+ const readyListener = UnifiedPlayerEvents.addListener(UnifiedPlayerEventTypes.READY, () => {
42
+ console.log('Player is ready to play');
43
+ // You can call UnifiedPlayer methods here, e.g., UnifiedPlayer.play(playerRef.current.getNativeTag());
44
+ });
45
+
46
+ const errorListener = UnifiedPlayerEvents.addListener(UnifiedPlayerEventTypes.ERROR, (error) => {
47
+ console.error('Player error:', error);
48
+ });
49
+
50
+ // Add other listeners as needed (PROGRESS, COMPLETE, STALLED, RESUMED)
51
+
52
+ return () => {
53
+ // Clean up listeners on unmount
54
+ readyListener.remove();
55
+ errorListener.remove();
56
+ // Remove other listeners
57
+ };
58
+ }, []);
59
+
60
+ return (
61
+ <View style={{ flex: 1 }}>
62
+ <UnifiedPlayerView
63
+ ref={playerRef}
64
+ style={{ width: '100%', height: 300 }} // Example style
65
+ videoUrl="YOUR_VIDEO_URL_HERE" // Replace with your video URL
66
+ autoplay={false} // Optional: set to true to autoplay
67
+ loop={false} // Optional: set to true to loop
68
+ // authToken="YOUR_AUTH_TOKEN" // Optional: for protected streams
69
+ // You can also use direct view props instead of or in addition to event listeners:
70
+ // onReadyToPlay={() => console.log('View prop: Ready to play')}
71
+ // onError={(e) => console.log('View prop: Error', e)}
72
+ // onPlaybackComplete={() => console.log('View prop: Playback complete')}
73
+ // onProgress={(data) => console.log('View prop: Progress', data)}
74
+ />
75
+ </View>
76
+ );
77
+ };
78
+
79
+ export default MyPlayerComponent;
104
80
  ```
105
81
 
106
- ### Events
82
+ ## Props
107
83
 
108
- #### URL Events
109
- - `onUrlLoad`: Fired when the video is loaded
110
- - `onUrlProgress`: Fired during video playback
111
- - `onUrlEnd`: Fired when video playback ends
112
- - `onUrlReadyForDisplay`: Fired when the video is ready to display
84
+ | Prop | Type | Required | Description |
85
+ |------|------|----------|-------------|
86
+ | `videoUrl` | `string` | Yes | Video source URL |
87
+ | `style` | `ViewStyle` | Yes | Apply custom styling |
88
+ | `autoplay` | `boolean` | No | Autoplay video when loaded |
89
+ | `loop` | `boolean` | No | Should video loop when finished |
90
+ | `authToken` | `string` | No | Optional auth token for protected streams |
91
+ | `onReadyToPlay` | `() => void` | No | Callback when video is ready to play |
92
+ | `onError` | `(error: any) => void` | No | Callback when an error occurs |
93
+ | `onPlaybackComplete` | `() => void` | No | Callback when video playback finishes |
94
+ | `onProgress` | `(data: { currentTime: number; duration: number }) => void` | No | Callback for playback progress |
113
95
 
114
- #### WebRTC Events
115
- - `onWebRTCConnected`: Fired when WebRTC connection is established
116
- - `onWebRTCDisconnected`: Fired when WebRTC connection is lost
117
- - `onWebRTCStats`: Fired with WebRTC connection statistics
96
+ ## Events
118
97
 
119
- #### Common Events
120
- - `onError`: Fired when an error occurs
98
+ Events can be listened to using `UnifiedPlayerEvents.addListener(eventType, listener)`. The available event types are defined in `UnifiedPlayerEventTypes`.
121
99
 
122
- ### Commands
100
+ - `UnifiedPlayerEventTypes.READY` ('onReadyToPlay'): Fired when the player is ready to play.
101
+ - `UnifiedPlayerEventTypes.ERROR` ('onError'): Fired when an error occurs.
102
+ - `UnifiedPlayerEventTypes.PROGRESS` ('onProgress'): Fired during playback with current time and duration (`{ currentTime: number; duration: number }`).
103
+ - `UnifiedPlayerEventTypes.COMPLETE` ('onPlaybackComplete'): Fired when video playback finishes.
104
+ - `UnifiedPlayerEventTypes.STALLED` ('onPlaybackStalled'): Fired when playback stalls.
105
+ - `UnifiedPlayerEventTypes.RESUMED` ('onPlaybackResumed'): Fired when playback resumes after stalling.
123
106
 
124
- The component supports the following commands:
107
+ ## Methods
125
108
 
126
- ```typescript
127
- // Seek to a specific time in the video
128
- seekUrl(viewRef: React.RefObject<YourUnifiedPlayerView>, timeSeconds: number): void;
109
+ Control playback using the `UnifiedPlayer` object and the native tag of the `UnifiedPlayerView` instance (obtained via `ref.current.getNativeTag()`).
129
110
 
130
- // Send a message through WebRTC data channel
131
- sendWebRTCMessage(viewRef: React.RefObject<YourUnifiedPlayerView>, message: string): void;
132
- ```
111
+ - `UnifiedPlayer.play(viewTag: number)`: Starts video playback.
112
+ - `UnifiedPlayer.pause(viewTag: number)`: Pauses video playback.
113
+ - `UnifiedPlayer.seekTo(viewTag: number, time: number)`: Seeks to a specific time in seconds.
114
+ - `UnifiedPlayer.getCurrentTime(viewTag: number): Promise<number>`: Gets the current playback time in seconds.
115
+ - `UnifiedPlayer.getDuration(viewTag: number): Promise<number>`: Gets the duration of the video in seconds.
133
116
 
134
117
  ## Development
135
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unified-player",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "Unified Player",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",