react-native-unified-player 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/LICENSE +20 -0
- package/README.md +95 -0
- package/UnifiedPlayer.podspec +32 -0
- package/android/build.gradle +81 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/AndroidManifestNew.xml +4 -0
- package/android/src/main/java/com/unifiedplayer/UnifiedPlayerEventEmitter.kt +62 -0
- package/android/src/main/java/com/unifiedplayer/UnifiedPlayerModule.kt +93 -0
- package/android/src/main/java/com/unifiedplayer/UnifiedPlayerPackage.kt +20 -0
- package/android/src/main/java/com/unifiedplayer/UnifiedPlayerView.kt +265 -0
- package/android/src/main/java/com/unifiedplayer/UnifiedPlayerViewManager.kt +33 -0
- package/ios/UnifiedPlayerModule.h +5 -0
- package/ios/UnifiedPlayerViewManager.m +670 -0
- package/lib/module/index.js +97 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/index.d.ts +46 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +154 -0
- package/src/index.tsx +135 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yaşar Özyurt
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# react-native-unified-player
|
|
2
|
+
|
|
3
|
+
Unified Player with VLC integration for enhanced codec and streaming protocol support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install react-native-unified-player
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### iOS Setup for VLC
|
|
12
|
+
|
|
13
|
+
The iOS version of this player uses MobileVLCKit for advanced video playback capabilities. It supports a wide range of formats including RTSP, RTMP, HLS, and other protocols supported by VLC.
|
|
14
|
+
|
|
15
|
+
The VLC dependencies are automatically installed via CocoaPods through the podspec file. After installing the package:
|
|
16
|
+
|
|
17
|
+
1. Navigate to the iOS folder of your project:
|
|
18
|
+
```sh
|
|
19
|
+
cd ios
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. Install pods:
|
|
23
|
+
```sh
|
|
24
|
+
pod install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
3. VLC requires "Bitcode" to be disabled in your Xcode project. This is handled automatically in the podspec file, but if you experience issues, check that your project's Build Settings have "Enable Bitcode" set to "No".
|
|
28
|
+
|
|
29
|
+
4. Starting from iOS 14, you need to provide a message for the `NSLocalNetworkUsageDescription` key in your `Info.plist` if you're using external streaming sources. Add something like:
|
|
30
|
+
```xml
|
|
31
|
+
<key>NSLocalNetworkUsageDescription</key>
|
|
32
|
+
<string>This app requires access to the local network to stream media content</string>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Troubleshooting VLC Integration
|
|
36
|
+
|
|
37
|
+
If you encounter build issues with VLC:
|
|
38
|
+
|
|
39
|
+
1. **Compilation Errors**: If you see errors about missing properties or methods, it might be because the VLC API has changed. This package uses MobileVLCKit 3.3.17, which is compatible with the current implementation.
|
|
40
|
+
|
|
41
|
+
2. **Playback Issues on iOS 14+**: VLC has known issues with certain RTSP streams on iOS 14. If you experience a black screen or playback failures specifically on newer iOS devices, try the following:
|
|
42
|
+
- Add additional media options in your code:
|
|
43
|
+
```js
|
|
44
|
+
// Example: Adding network caching for better buffering
|
|
45
|
+
<UnifiedPlayerView
|
|
46
|
+
videoUrl="rtsp://example.com/stream"
|
|
47
|
+
mediaOptions={["--network-caching=1500", "--live-caching=1500"]}
|
|
48
|
+
/>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. **Link Required Frameworks**: Make sure you have all required frameworks linked in your Xcode project:
|
|
52
|
+
- AudioToolbox.framework
|
|
53
|
+
- AVFoundation.framework
|
|
54
|
+
- CoreMedia.framework
|
|
55
|
+
- CoreVideo.framework
|
|
56
|
+
- libc++.tbd
|
|
57
|
+
- libiconv.tbd
|
|
58
|
+
- libz.tbd
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import { UnifiedPlayerView } from "react-native-unified-player";
|
|
64
|
+
|
|
65
|
+
// ...
|
|
66
|
+
|
|
67
|
+
<UnifiedPlayerView
|
|
68
|
+
videoUrl="https://example.com/video.mp4"
|
|
69
|
+
autoplay={true}
|
|
70
|
+
loop={false}
|
|
71
|
+
authToken="optional-auth-token"
|
|
72
|
+
/>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Supported Formats
|
|
76
|
+
|
|
77
|
+
With VLC integration, the player supports a wide range of formats:
|
|
78
|
+
|
|
79
|
+
- Network streams: RTSP, RTP, RTMP, HLS, MMS
|
|
80
|
+
- Container formats: MP4, MKV, AVI, FLV, MOV, TS, and many more
|
|
81
|
+
- Codec support: H.264, H.265, VP8, VP9, and many others
|
|
82
|
+
- Audio: Multiple audio tracks support including 5.1
|
|
83
|
+
- Subtitles: Support for various subtitle formats including SSA
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "UnifiedPlayer"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/blueromans/react-native-unified-player.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
|
|
18
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
19
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
20
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
21
|
+
install_modules_dependencies(s)
|
|
22
|
+
else
|
|
23
|
+
s.dependency "React-Core"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Add MobileVLCKit dependency with exact version to avoid compatibility issues
|
|
27
|
+
s.dependency "MobileVLCKit", "3.3.17"
|
|
28
|
+
|
|
29
|
+
# Disable bitcode to match VLC requirements
|
|
30
|
+
s.pod_target_xcconfig = { "ENABLE_BITCODE" => "NO" }
|
|
31
|
+
s.user_target_xcconfig = { "ENABLE_BITCODE" => "NO" }
|
|
32
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['UnifiedPlayer_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:7.3.1"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: "com.android.library"
|
|
19
|
+
apply plugin: "kotlin-android"
|
|
20
|
+
|
|
21
|
+
def getExtOrIntegerDefault(name) {
|
|
22
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["UnifiedPlayer_" + name]).toInteger()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def supportsNamespace() {
|
|
26
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
27
|
+
def major = parsed[0].toInteger()
|
|
28
|
+
def minor = parsed[1].toInteger()
|
|
29
|
+
|
|
30
|
+
// Namespace support was added in 7.3.0
|
|
31
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
android {
|
|
35
|
+
if (supportsNamespace()) {
|
|
36
|
+
namespace "com.unifiedplayer"
|
|
37
|
+
|
|
38
|
+
sourceSets {
|
|
39
|
+
main {
|
|
40
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
46
|
+
|
|
47
|
+
defaultConfig {
|
|
48
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
49
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
buildTypes {
|
|
53
|
+
release {
|
|
54
|
+
minifyEnabled false
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
lintOptions {
|
|
59
|
+
disable "GradleCompatible"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
compileOptions {
|
|
63
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
64
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
repositories {
|
|
69
|
+
mavenCentral()
|
|
70
|
+
google()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
74
|
+
|
|
75
|
+
dependencies {
|
|
76
|
+
implementation "com.facebook.react:react-android"
|
|
77
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
78
|
+
|
|
79
|
+
implementation "com.google.android.exoplayer:exoplayer-core:2.18.1"
|
|
80
|
+
implementation "com.google.android.exoplayer:exoplayer-ui:2.18.1"
|
|
81
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="com.unifiedplayer">
|
|
3
|
+
<uses-permission android:name="android.permission.INTERNET" />
|
|
4
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
5
|
+
<application android:hardwareAccelerated="true">
|
|
6
|
+
</application>
|
|
7
|
+
</manifest>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package com.unifiedplayer
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.bridge.WritableMap
|
|
7
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
8
|
+
import android.util.Log
|
|
9
|
+
|
|
10
|
+
class UnifiedPlayerEventEmitter(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
11
|
+
companion object {
|
|
12
|
+
private const val TAG = "UnifiedPlayerEventEmitter"
|
|
13
|
+
|
|
14
|
+
// Define all possible event types
|
|
15
|
+
const val EVENT_READY = "onReadyToPlay"
|
|
16
|
+
const val EVENT_ERROR = "onError"
|
|
17
|
+
const val EVENT_PROGRESS = "onProgress"
|
|
18
|
+
const val EVENT_COMPLETE = "onPlaybackComplete"
|
|
19
|
+
const val EVENT_STALLED = "onPlaybackStalled"
|
|
20
|
+
const val EVENT_RESUMED = "onPlaybackResumed"
|
|
21
|
+
|
|
22
|
+
// Singleton instance for access from other classes
|
|
23
|
+
private var instance: UnifiedPlayerEventEmitter? = null
|
|
24
|
+
|
|
25
|
+
fun getInstance(): UnifiedPlayerEventEmitter? {
|
|
26
|
+
return instance
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
init {
|
|
31
|
+
instance = this
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override fun getName(): String {
|
|
35
|
+
return "UnifiedPlayerEvents"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@ReactMethod
|
|
39
|
+
fun addListener(eventName: String) {
|
|
40
|
+
// Required for React Native event emitter
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@ReactMethod
|
|
44
|
+
fun removeListeners(count: Int) {
|
|
45
|
+
// Required for React Native event emitter
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fun sendEvent(eventName: String, params: WritableMap?) {
|
|
49
|
+
try {
|
|
50
|
+
reactContext
|
|
51
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
52
|
+
.emit(eventName, params)
|
|
53
|
+
} catch (e: Exception) {
|
|
54
|
+
Log.e(TAG, "Error sending event: $eventName - ${e.message}")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun onCatalystInstanceDestroy() {
|
|
59
|
+
super.onCatalystInstanceDestroy()
|
|
60
|
+
instance = null
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
package com.unifiedplayer
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.uimanager.UIManagerModule
|
|
8
|
+
import android.util.Log
|
|
9
|
+
|
|
10
|
+
class UnifiedPlayerModule(private val reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
11
|
+
companion object {
|
|
12
|
+
private const val TAG = "UnifiedPlayerModule"
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
override fun getName(): String {
|
|
16
|
+
return "UnifiedPlayer"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private fun getPlayerView(viewId: Int): UnifiedPlayerView? {
|
|
20
|
+
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
|
|
21
|
+
val view = uiManager?.resolveView(viewId) as? UnifiedPlayerView
|
|
22
|
+
|
|
23
|
+
if (view == null) {
|
|
24
|
+
Log.e(TAG, "Unable to find UnifiedPlayerView with id $viewId")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return view
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@ReactMethod
|
|
31
|
+
fun play(viewId: Int) {
|
|
32
|
+
try {
|
|
33
|
+
Log.d(TAG, "Play command received for view $viewId")
|
|
34
|
+
reactContext.runOnUiQueueThread {
|
|
35
|
+
getPlayerView(viewId)?.play()
|
|
36
|
+
}
|
|
37
|
+
} catch (e: Exception) {
|
|
38
|
+
Log.e(TAG, "Error playing video: ${e.message}")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
fun pause(viewId: Int) {
|
|
44
|
+
try {
|
|
45
|
+
Log.d(TAG, "Pause command received for view $viewId")
|
|
46
|
+
reactContext.runOnUiQueueThread {
|
|
47
|
+
getPlayerView(viewId)?.pause()
|
|
48
|
+
}
|
|
49
|
+
} catch (e: Exception) {
|
|
50
|
+
Log.e(TAG, "Error pausing video: ${e.message}")
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ReactMethod
|
|
55
|
+
fun seekTo(viewId: Int, time: Float) {
|
|
56
|
+
try {
|
|
57
|
+
Log.d(TAG, "Seek command received for view $viewId to time $time")
|
|
58
|
+
reactContext.runOnUiQueueThread {
|
|
59
|
+
getPlayerView(viewId)?.seekTo(time)
|
|
60
|
+
}
|
|
61
|
+
} catch (e: Exception) {
|
|
62
|
+
Log.e(TAG, "Error seeking: ${e.message}")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactMethod
|
|
67
|
+
fun getCurrentTime(viewId: Int, promise: Promise) {
|
|
68
|
+
try {
|
|
69
|
+
Log.d(TAG, "Get current time for view $viewId")
|
|
70
|
+
reactContext.runOnUiQueueThread {
|
|
71
|
+
val time = getPlayerView(viewId)?.getCurrentTime() ?: 0f
|
|
72
|
+
promise.resolve(time)
|
|
73
|
+
}
|
|
74
|
+
} catch (e: Exception) {
|
|
75
|
+
Log.e(TAG, "Error getting current time: ${e.message}")
|
|
76
|
+
promise.reject("ERROR", "Failed to get current time: ${e.message}")
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ReactMethod
|
|
81
|
+
fun getDuration(viewId: Int, promise: Promise) {
|
|
82
|
+
try {
|
|
83
|
+
Log.d(TAG, "Get duration for view $viewId")
|
|
84
|
+
reactContext.runOnUiQueueThread {
|
|
85
|
+
val duration = getPlayerView(viewId)?.getDuration() ?: 0f
|
|
86
|
+
promise.resolve(duration)
|
|
87
|
+
}
|
|
88
|
+
} catch (e: Exception) {
|
|
89
|
+
Log.e(TAG, "Error getting duration: ${e.message}")
|
|
90
|
+
promise.reject("ERROR", "Failed to get duration: ${e.message}")
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package com.unifiedplayer
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class UnifiedPlayerPackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
+
return listOf(
|
|
12
|
+
UnifiedPlayerModule(reactContext),
|
|
13
|
+
UnifiedPlayerEventEmitter(reactContext)
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
18
|
+
return listOf(UnifiedPlayerViewManager())
|
|
19
|
+
}
|
|
20
|
+
}
|