react-native-tpstreams 0.1.13 → 0.1.15

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 CHANGED
@@ -75,7 +75,7 @@ The player component accepts the following props:
75
75
  | `enableDownload` | boolean | No | `true` | Enables or disables video download. |
76
76
  | `autoPlay` | boolean | No | `true` | Controls whether the video should start playing automatically. |
77
77
  | `startAt` | number | No | `0` | Start the video from a particular time (in seconds). |
78
- | `offlineLicenseExpireTime` | number | No | `15` | DRM license expiration time in days. |
78
+ | `offlineLicenseExpireTime` | number | No | `1296000(15 days in seconds)` | DRM license expiration time in seconds. |
79
79
  | `style` | object | No | `{ width: '100%', height: 300 }` | Defines the player’s width and height. |
80
80
 
81
81
  # Player Methods
@@ -110,7 +110,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
110
110
  dependencies {
111
111
  implementation "com.facebook.react:react-android"
112
112
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
113
- implementation "com.tpstreams.player:player:3.1.6"
113
+ implementation "com.tpstreams.player:player:3.1.7"
114
114
  }
115
115
 
116
116
  if (isNewArchitectureEnabled()) {
@@ -16,6 +16,9 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
16
16
  import com.tpstream.player.data.Asset
17
17
  import com.tpstream.player.offline.TpStreamDownloadManager
18
18
  import com.tpstream.player.TPStreamsSDK
19
+ import com.facebook.react.bridge.ReadableMap
20
+ import com.facebook.react.bridge.WritableNativeMap
21
+
19
22
 
20
23
  class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
21
24
 
@@ -35,7 +38,15 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
35
38
  }
36
39
 
37
40
  @ReactMethod
38
- fun showCustomFragment(videoId: String, accessToken: String, enableDownload: Boolean, autoPlay: Boolean, startAt: Int, offlineLicenseExpireTime: Int) {
41
+ fun showCustomFragment(
42
+ videoId: String,
43
+ accessToken: String,
44
+ enableDownload: Boolean,
45
+ autoPlay: Boolean,
46
+ startAt: Int,
47
+ offlineLicenseExpireTime: Int,
48
+ downloadMetadata: ReadableMap?,
49
+ ) {
39
50
  Log.e("FragmentModule", "showCustomFragment() called")
40
51
  // Ensure the currentActivity is a FragmentActivity
41
52
  val activity = currentActivity as? FragmentActivity
@@ -51,6 +62,7 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
51
62
  bundle.putBoolean("AUTO_PLAY", autoPlay)
52
63
  bundle.putInt("START_AT", startAt)
53
64
  bundle.putInt("OFFLINE_LICENSE_EXPIRE_TIME", offlineLicenseExpireTime)
65
+ bundle.putSerializable("DOWNLOAD_METADATA", downloadMetadata?.toHashMapString())
54
66
  val fragment = PlayerFragment()
55
67
  fragment.setArguments(bundle)
56
68
 
@@ -115,7 +127,7 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
115
127
  assetMap.putString("percentage", asset.video.percentageDownloaded.toString())
116
128
  assetMap.putString("status", asset.video.downloadState?.name ?: "Unknown")
117
129
  assetMap.putString("duration", asset.video.duration.toString())
118
-
130
+ assetMap.putMap("metadata", asset.metadata?.toWritableMap() ?: null)
119
131
  assetsList.pushMap(assetMap)
120
132
  }
121
133
 
@@ -130,6 +142,27 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
130
142
  }
131
143
  }
132
144
 
145
+ fun ReadableMap.toHashMapString(): HashMap<String, String> {
146
+ val result = HashMap<String, String>()
147
+ val iterator = this.keySetIterator()
148
+ while (iterator.hasNextKey()) {
149
+ val key = iterator.nextKey()
150
+ val value = this.getString(key) // Ensuring values are strings
151
+ if (value != null) {
152
+ result[key] = value
153
+ }
154
+ }
155
+ return result
156
+ }
157
+
158
+ fun Map<String, String>.toWritableMap(): ReadableMap {
159
+ val writableMap: WritableMap = WritableNativeMap()
160
+ for ((key, value) in this) {
161
+ writableMap.putString(key, value)
162
+ }
163
+ return writableMap
164
+ }
165
+
133
166
  @ReactMethod
134
167
  fun pauseDownload(videoId: String) {
135
168
  val asset = assets.first { it.id == videoId }
@@ -32,6 +32,7 @@ class PlayerFragment : Fragment() {
32
32
  private var setAutoPlay :Boolean = true
33
33
  private var startAt :Int = 0
34
34
  private var offlineLicenseExpireTime :Int = 60 * 60 * 24 * 15 //15 days
35
+ private var downloadMetadata: HashMap<String, String>? = null
35
36
 
36
37
  private var accessTokenCallback : onAccessTokenCallbase? = null
37
38
 
@@ -49,7 +50,7 @@ class PlayerFragment : Fragment() {
49
50
  setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
50
51
  startAt = bundle.getInt("START_AT", 0)
51
52
  offlineLicenseExpireTime = bundle.getInt("OFFLINE_LICENSE_EXPIRE_TIME", offlineLicenseExpireTime)
52
-
53
+ downloadMetadata = bundle.getSerializable("DOWNLOAD_METADATA") as? HashMap<String, String>
53
54
  }
54
55
  }
55
56
 
@@ -85,9 +86,12 @@ class PlayerFragment : Fragment() {
85
86
  .setOfflineLicenseExpireTime(offlineLicenseExpireTime)
86
87
  .build()
87
88
  requireActivity().runOnUiThread {
88
- player.load(parameters)
89
+ player.load(parameters, getMetadata())
89
90
  }
90
91
  }
92
+ private fun getMetadata(): HashMap<String, String> {
93
+ return downloadMetadata ?: hashMapOf()
94
+ }
91
95
 
92
96
  private fun sendEvent(eventName: String, params: Any?) {
93
97
  TpstreamsModule.sendEvent(eventName, params)
@@ -147,6 +151,10 @@ class PlayerFragment : Fragment() {
147
151
  override fun onTracksChanged(tracks: Tracks) {
148
152
  sendEvent("onTracksChanged", tracks.toString())
149
153
  }
154
+
155
+ override fun onPlaybackSpeedChange(speed: Float) {
156
+ sendEvent("onPlaybackSpeedChanged", speed)
157
+ }
150
158
  })
151
159
  }
152
160
  // Core Player Controls
@@ -6,6 +6,8 @@ import android.util.AttributeSet
6
6
  import android.widget.FrameLayout
7
7
  import androidx.fragment.app.FragmentActivity
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
+ import com.facebook.react.bridge.ReadableMap
10
+ import com.facebook.react.bridge.WritableMap
9
11
  import com.facebook.react.uimanager.ThemedReactContext
10
12
 
11
13
  class TpStreamsPlayerView @JvmOverloads constructor(
@@ -19,6 +21,7 @@ class TpStreamsPlayerView @JvmOverloads constructor(
19
21
  private var autoPlay :Boolean = true
20
22
  private var startAt :Int = 0
21
23
  private var offlineLicenseExpireTime :Int = 60 * 60 * 24 * 15
24
+ private var downloadMetadata: ReadableMap? = null
22
25
  private var fragmentModule: FragmentModule? = null
23
26
 
24
27
  private val job = SupervisorJob()
@@ -66,6 +69,11 @@ class TpStreamsPlayerView @JvmOverloads constructor(
66
69
  updateFragment()
67
70
  }
68
71
 
72
+ fun setDownloadMetadata(metadata: ReadableMap?) {
73
+ downloadMetadata = metadata ?: null
74
+ updateFragment()
75
+ }
76
+
69
77
  private fun updateFragment() {
70
78
  if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
71
79
  updateJob?.cancel()
@@ -79,6 +87,7 @@ class TpStreamsPlayerView @JvmOverloads constructor(
79
87
  autoPlay ?: true,
80
88
  startAt,
81
89
  offlineLicenseExpireTime,
90
+ downloadMetadata,
82
91
  )
83
92
  }
84
93
  }
@@ -3,6 +3,7 @@ package com.tpstreams
3
3
  import com.facebook.react.uimanager.SimpleViewManager
4
4
  import com.facebook.react.uimanager.ThemedReactContext
5
5
  import com.facebook.react.uimanager.annotations.ReactProp
6
+ import com.facebook.react.bridge.ReadableMap
6
7
 
7
8
  class TpStreamsPlayerViewManager : SimpleViewManager<TpStreamsPlayerView>() {
8
9
 
@@ -39,7 +40,12 @@ class TpStreamsPlayerViewManager : SimpleViewManager<TpStreamsPlayerView>() {
39
40
 
40
41
  @ReactProp(name = "offlineLicenseExpireTime")
41
42
  fun setOfflineLicenseExpireTime(view: TpStreamsPlayerView, offlineLicenseExpireTime: Int?) {
42
- view.setOfflineLicenseExpireTime(offlineLicenseExpireTime ?: 15)
43
+ view.setOfflineLicenseExpireTime(offlineLicenseExpireTime ?: 60 * 60 * 24 * 15)
44
+ }
45
+
46
+ @ReactProp(name = "downloadMetadata")
47
+ fun setDownloadMetadata(view: TpStreamsPlayerView, downloadMetadata: ReadableMap?) {
48
+ downloadMetadata?.let { view.setDownloadMetadata(downloadMetadata) }
43
49
  }
44
50
  }
45
51
 
@@ -5,6 +5,7 @@ export type TpStreamsPlayerProps = {
5
5
  autoPlay?: boolean;
6
6
  startAt?: number;
7
7
  offlineLicenseExpireTime?: number;
8
+ downloadMetadata?: Record<string, string>;
8
9
  style?: import('react-native').ViewStyle;
9
10
  };
10
11
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
@@ -5,6 +5,7 @@ export type TpStreamsPlayerProps = {
5
5
  autoPlay?: boolean;
6
6
  startAt?: number;
7
7
  offlineLicenseExpireTime?: number;
8
+ downloadMetadata?: Record<string, string>;
8
9
  style?: import('react-native').ViewStyle;
9
10
  };
10
11
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-tpstreams",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Video Component for TPStreams",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
package/src/types.ts CHANGED
@@ -5,5 +5,6 @@ export type TpStreamsPlayerProps = {
5
5
  autoPlay?: boolean;
6
6
  startAt?: number;
7
7
  offlineLicenseExpireTime?: number;
8
+ downloadMetadata?: Record<string, string>;
8
9
  style?: import('react-native').ViewStyle;
9
10
  };