react-native-tpstreams 0.2.18 → 0.2.19
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.
|
@@ -11,6 +11,7 @@ import com.tpstreams.player.TPStreamsPlayerView
|
|
|
11
11
|
import androidx.media3.common.Player
|
|
12
12
|
import androidx.media3.common.PlaybackParameters
|
|
13
13
|
import androidx.media3.common.PlaybackException
|
|
14
|
+
import android.media.MediaCodec
|
|
14
15
|
|
|
15
16
|
class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context) {
|
|
16
17
|
private val playerView: TPStreamsPlayerView = TPStreamsPlayerView(context)
|
|
@@ -19,6 +20,8 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
19
20
|
|
|
20
21
|
companion object {
|
|
21
22
|
private const val DEFAULT_OFFLINE_LICENSE_EXPIRE_TIME = 15L * 24L * 60L * 60L // 15 days in seconds
|
|
23
|
+
private const val ERROR_CODE_PLAYER_CREATION_FAILED = 1001
|
|
24
|
+
private const val ERROR_CODE_DRM_LICENSE_EXPIRED = 5001
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
private var videoId: String? = null
|
|
@@ -141,7 +144,7 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
141
144
|
emitEvent("onIsLoadingChanged", mapOf("isLoading" to false))
|
|
142
145
|
} catch (e: Exception) {
|
|
143
146
|
Log.e("TPStreamsRN", "Error creating player", e)
|
|
144
|
-
sendErrorEvent("Error creating player",
|
|
147
|
+
sendErrorEvent("Error creating player", ERROR_CODE_PLAYER_CREATION_FAILED, e.message)
|
|
145
148
|
}
|
|
146
149
|
}
|
|
147
150
|
|
|
@@ -165,11 +168,23 @@ class TPStreamsRNPlayerView(context: ThemedReactContext) : FrameLayout(context)
|
|
|
165
168
|
|
|
166
169
|
override fun onPlayerError(error: PlaybackException) {
|
|
167
170
|
Log.e("TPStreamsRN", "Player error", error)
|
|
171
|
+
if (isDrmLicenseExpiredError(error)) {
|
|
172
|
+
sendErrorEvent("Playback error", ERROR_CODE_DRM_LICENSE_EXPIRED, "Offline DRM license expired")
|
|
173
|
+
return
|
|
174
|
+
}
|
|
168
175
|
sendErrorEvent("Playback error", error.errorCode, error.message)
|
|
169
176
|
}
|
|
170
177
|
}
|
|
171
178
|
}
|
|
172
179
|
|
|
180
|
+
private fun isDrmLicenseExpiredError(error: PlaybackException): Boolean {
|
|
181
|
+
val cause = error.cause
|
|
182
|
+
return error.errorCode == PlaybackException.ERROR_CODE_DRM_LICENSE_EXPIRED ||
|
|
183
|
+
error.errorCode == PlaybackException.ERROR_CODE_DRM_DISALLOWED_OPERATION ||
|
|
184
|
+
error.errorCode == PlaybackException.ERROR_CODE_DRM_SYSTEM_ERROR ||
|
|
185
|
+
cause is MediaCodec.CryptoException
|
|
186
|
+
}
|
|
187
|
+
|
|
173
188
|
// Player control methods
|
|
174
189
|
fun play() {
|
|
175
190
|
player?.play()
|