@takeoffmedia/react-native-penthera 0.2.48 → 0.2.50

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.
@@ -4,10 +4,8 @@ import android.annotation.SuppressLint
4
4
  import android.app.Activity
5
5
  import android.content.Context
6
6
  import android.util.Log
7
- import android.widget.Toast
8
- import com.bitmovin.player.api.ui.StyleConfig
9
7
  import com.bitmovin.player.reactnative.PlayerModule
10
- import com.bitmovin.player.reactnative.extensions.setProperty
8
+ import com.bitmovin.player.reactnative.converter.JsonConverter
11
9
 
12
10
  import com.facebook.react.bridge.ReactApplicationContext
13
11
  import com.google.gson.Gson
@@ -29,9 +27,13 @@ import com.facebook.react.bridge.Arguments
29
27
  import com.facebook.react.uimanager.UIManagerModule
30
28
  import com.facebook.react.bridge.Promise
31
29
  import com.facebook.react.bridge.ReadableArray
30
+ import com.facebook.react.bridge.ReadableMap
31
+
32
32
  import com.penthera.virtuososdk.client.AncillaryFile
33
+ import org.json.JSONArray
33
34
  import org.json.JSONObject
34
- import java.util.Arrays
35
+ import java.text.SimpleDateFormat
36
+ import java.util.Calendar
35
37
 
36
38
  class OfflineVideoEngine(private val context: ReactApplicationContext) {
37
39
 
@@ -127,6 +129,22 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
127
129
  )
128
130
  )
129
131
 
132
+ val subtitles = JSONArray(item["subtitles"] as String)
133
+ for (i in 0 until subtitles.length()) {
134
+ val subtitle = subtitles.getJSONObject(i)
135
+ val language = subtitle["language"] as String
136
+ val href = subtitle["href"]
137
+ fileList.add(
138
+ AncillaryFile(
139
+ URL(href.toString()),
140
+ language,
141
+ arrayOf(language),
142
+ language,
143
+ URL(href.toString())
144
+ )
145
+ )
146
+ }
147
+
130
148
  val params = MPDAssetBuilder().apply {
131
149
  assetId(assetId)
132
150
  manifestUrl(URL(url))
@@ -154,6 +172,8 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
154
172
  while (cursor?.moveToNext() == true && columnNames != null) {
155
173
  val assetManager = virtuoso.assetManager
156
174
  val dataMap = mutableMapOf<String, Any>()
175
+ var eap = ""
176
+ var ead = ""
157
177
  for (columnName in columnNames) {
158
178
  val columnIndex = cursor.getColumnIndex(columnName)
159
179
  if (columnIndex >= 0) {
@@ -180,6 +200,20 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
180
200
  put("estimatedSize", value)
181
201
  }
182
202
  }
203
+ if (columnName == "ead") {
204
+ ead = value
205
+ }
206
+ if (columnName == "eap") {
207
+ eap = value
208
+ }
209
+ if (columnName == "firstPlayTime") {
210
+ var eadFormated = dateToString(ead)
211
+ var eapFormated = dateToString(eap)
212
+ dataMap["data"] = (dataMap["data"] as? MutableMap<String, Any> ?: mutableMapOf()).apply {
213
+ put("effectiveExpiryDate", if (value == "0") eadFormated else eapFormated)
214
+ }
215
+ }
216
+
183
217
  }
184
218
  }
185
219
  dataMap["isCompleted"] = dataMap["currentSize"] == dataMap["expectedSize"]
@@ -191,21 +225,30 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
191
225
  return gson.toJson(completedList)
192
226
  }
193
227
 
228
+ private fun dateToString(seconds: String): String {
229
+ val secondsLong = seconds.toLong()
230
+ val calendar = Calendar.getInstance()
231
+ calendar.add(Calendar.SECOND, secondsLong.toInt())
232
+
233
+ val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
234
+ return dateFormat.format(calendar.time)
235
+ }
236
+
194
237
  class AssetParseObserver(activity: Context) : ISegmentedAssetFromParserObserver {
195
238
  private val mActivity: Context = activity
196
239
 
197
240
  @SuppressLint("ShowToast")
198
241
  override fun complete(asset: ISegmentedAsset?, error: Int, addedToQueue: Boolean) {
199
-
200
- if (asset != null) {
201
- Toast.makeText(
202
- mActivity,
203
- "Asset parsed and " + if (addedToQueue) "added" else "not added" + "to download queue",
204
- Toast.LENGTH_LONG
205
- ).show()
206
- } else {
207
- Toast.makeText(mActivity, "Error $error while parsing asset", Toast.LENGTH_LONG).show()
208
- }
242
+ // Show a process when the asset to parsed and added to queue
243
+ // if (asset != null) {
244
+ // Toast.makeText(
245
+ // mActivity,
246
+ // "Asset parsed and " + if (addedToQueue) "added" else "not added" + "to download queue",
247
+ // Toast.LENGTH_LONG
248
+ // ).show()
249
+ // } else {
250
+ // Toast.makeText(mActivity, "Error $error while parsing asset", Toast.LENGTH_LONG).show()
251
+ // }
209
252
  }
210
253
  }
211
254
 
@@ -251,16 +294,33 @@ class OfflineVideoEngine(private val context: ReactApplicationContext) {
251
294
 
252
295
  fun updateUI() {}
253
296
 
254
-
255
297
  fun loadBitmovinSourceManager(assetId: String, nativeId: String): Boolean {
256
298
  virtuoso.assetManager?.getByAssetId(assetId)?.firstOrNull()?.let { asset ->
299
+
257
300
  val sourceManager = BitmovinSourceManager(context, asset as ISegmentedAsset)
258
301
  val sourceItem = sourceManager.bitmovinSourceItem
259
302
  val playerModule = context.getNativeModule(PlayerModule::class.java)
260
303
  if (playerModule != null && sourceItem != null) {
261
304
  val player = playerModule.getPlayer(nativeId)
262
-
263
305
  if (player != null) {
306
+
307
+ val subtitles = JSONArray(JSONObject(asset.metadata)["subtitles"] as String)
308
+ val ancillaryFiles = (asset as ISegmentedAsset).getAncillaryFiles(context)
309
+ for (i in 0 until subtitles.length()) {
310
+ val subtitle = subtitles.getJSONObject(i)
311
+ val subtitleMap = Arguments.createMap()
312
+ ancillaryFiles.find { it.description == subtitle.getString("language") }?.let {
313
+ subtitleMap.putString("url", it.playbackUrl.toString())
314
+ }
315
+ subtitleMap.putString("language", subtitle.getString("language"))
316
+ subtitleMap.putString("label", subtitle.getString("label"))
317
+ subtitleMap.putString("format", "vtt")
318
+
319
+ JsonConverter.toSubtitleTrack(subtitleMap)?.let {
320
+ sourceItem.addSubtitleTrack(it)
321
+ }
322
+ }
323
+
264
324
  player.load(sourceItem)
265
325
  return true
266
326
  }
@@ -27,7 +27,8 @@ class ServiceStarter : VirtuosoServiceStarter() {
27
27
  }
28
28
 
29
29
  // This is a helper class which is used in the demo for creating the notifications
30
- private val notificationFactory: NotificationFactory = NotificationFactory("PentheraExample")
30
+ //Name notification channel
31
+ private val notificationFactory: NotificationFactory = NotificationFactory("Britbox")
31
32
 
32
33
  /**
33
34
  * This method will be called by the framework to request the generation of a notification,
@@ -62,4 +63,4 @@ class ServiceStarter : VirtuosoServiceStarter() {
62
63
  return ServiceForegroundNotificationProvider::class.java
63
64
  }
64
65
 
65
- }
66
+ }
@@ -91,8 +91,9 @@ class ServiceForegroundNotificationProvider : IForegroundNotificationProvider{
91
91
  override fun getForegroundServiceNotification(context: Context?, file: IAsset?, reasonIntent: Intent?): Notification {
92
92
  if (reasonIntent == null) return currentNotification!!
93
93
 
94
- currentNotification = NotificationFactory("PentheraExample").getNotification(context!!, reasonIntent )
94
+ //Name notification channel
95
+ currentNotification = NotificationFactory("Britbox").getNotification(context!!, reasonIntent )
95
96
 
96
97
  return currentNotification!!
97
98
  }
98
- }
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeoffmedia/react-native-penthera",
3
- "version": "0.2.48",
3
+ "version": "0.2.50",
4
4
  "description": "test",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -166,4 +166,4 @@
166
166
  "dependencies": {
167
167
  "zustand": "^4.4.0"
168
168
  }
169
- }
169
+ }