react-native-tpstreams 0.1.2 → 0.1.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.
- package/android/src/main/java/com/tpstreams/FragmentModule.kt +3 -1
- package/android/src/main/java/com/tpstreams/PlayerFragment.kt +7 -2
- package/android/src/main/java/com/tpstreams/TpStreamsPlayerView.kt +30 -3
- package/android/src/main/java/com/tpstreams/TpStreamsPlayerViewManager.kt +11 -0
- package/lib/typescript/commonjs/src/types.d.ts +2 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +2 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/types.ts +2 -0
|
@@ -35,7 +35,7 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
@ReactMethod
|
|
38
|
-
fun showCustomFragment(videoId: String, accessToken: String) {
|
|
38
|
+
fun showCustomFragment(videoId: String, accessToken: String, enableDownload: Boolean, autoPlay: Boolean) {
|
|
39
39
|
Log.e("FragmentModule", "showCustomFragment() called")
|
|
40
40
|
// Ensure the currentActivity is a FragmentActivity
|
|
41
41
|
val activity = currentActivity as? FragmentActivity
|
|
@@ -47,6 +47,8 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
|
|
|
47
47
|
val bundle = Bundle()
|
|
48
48
|
bundle.putString("VIDEO_ID", videoId)
|
|
49
49
|
bundle.putString("ACCESS_TOKEN", accessToken)
|
|
50
|
+
bundle.putBoolean("ENABLE_DOWNLOAD_SUPPORT", enableDownload)
|
|
51
|
+
bundle.putBoolean("AUTO_PLAY", autoPlay)
|
|
50
52
|
val fragment = PlayerFragment()
|
|
51
53
|
fragment.setArguments(bundle)
|
|
52
54
|
|
|
@@ -21,6 +21,8 @@ class PlayerFragment : Fragment() {
|
|
|
21
21
|
lateinit var playerFragment: TpStreamPlayerFragment
|
|
22
22
|
private var videoId :String = ""
|
|
23
23
|
private var accessToken :String = ""
|
|
24
|
+
private var enableDownloadSupport :Boolean = true
|
|
25
|
+
private var setAutoPlay :Boolean = true
|
|
24
26
|
|
|
25
27
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
26
28
|
super.onCreate(savedInstanceState)
|
|
@@ -28,6 +30,9 @@ class PlayerFragment : Fragment() {
|
|
|
28
30
|
if (bundle != null) {
|
|
29
31
|
videoId = bundle.getString("VIDEO_ID") ?: ""
|
|
30
32
|
accessToken = bundle.getString("ACCESS_TOKEN") ?: ""
|
|
33
|
+
enableDownloadSupport = bundle.getBoolean("ENABLE_DOWNLOAD_SUPPORT", true)
|
|
34
|
+
setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
|
|
35
|
+
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
@@ -56,8 +61,8 @@ class PlayerFragment : Fragment() {
|
|
|
56
61
|
val parameters = TpInitParams.Builder()
|
|
57
62
|
.setVideoId(videoId)
|
|
58
63
|
.setAccessToken(accessToken)
|
|
59
|
-
.enableDownloadSupport(
|
|
60
|
-
.setAutoPlay(
|
|
64
|
+
.enableDownloadSupport(enableDownloadSupport)
|
|
65
|
+
.setAutoPlay(setAutoPlay)
|
|
61
66
|
.build()
|
|
62
67
|
player.load(parameters)
|
|
63
68
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.tpstreams
|
|
2
2
|
|
|
3
|
+
import kotlinx.coroutines.*
|
|
3
4
|
import android.content.Context
|
|
4
5
|
import android.util.AttributeSet
|
|
5
6
|
import android.widget.FrameLayout
|
|
@@ -10,12 +11,18 @@ import com.facebook.react.uimanager.ThemedReactContext
|
|
|
10
11
|
class TpStreamsPlayerView @JvmOverloads constructor(
|
|
11
12
|
context: Context,
|
|
12
13
|
attrs: AttributeSet? = null
|
|
13
|
-
) : FrameLayout(context, attrs) {
|
|
14
|
+
) : FrameLayout(context, attrs), CoroutineScope {
|
|
14
15
|
|
|
15
16
|
private var videoId: String? = null
|
|
16
17
|
private var accessToken: String? = null
|
|
18
|
+
private var enableDownload: Boolean = true
|
|
19
|
+
private var autoPlay :Boolean = true
|
|
17
20
|
private var fragmentModule: FragmentModule? = null
|
|
18
21
|
|
|
22
|
+
private val job = SupervisorJob()
|
|
23
|
+
override val coroutineContext = Dispatchers.Main + job
|
|
24
|
+
private var updateJob: Job? = null
|
|
25
|
+
|
|
19
26
|
init {
|
|
20
27
|
if (context is ThemedReactContext) {
|
|
21
28
|
val reactContext = context.reactApplicationContext
|
|
@@ -37,15 +44,35 @@ class TpStreamsPlayerView @JvmOverloads constructor(
|
|
|
37
44
|
updateFragment()
|
|
38
45
|
}
|
|
39
46
|
|
|
47
|
+
fun setEnableDownload(enableDownload: Boolean?) {
|
|
48
|
+
this.enableDownload = enableDownload ?: true
|
|
49
|
+
updateFragment()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fun setAutoPlay(autoPlay: Boolean?) {
|
|
53
|
+
this.autoPlay = autoPlay ?: true
|
|
54
|
+
updateFragment()
|
|
55
|
+
}
|
|
56
|
+
|
|
40
57
|
private fun updateFragment() {
|
|
41
58
|
if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
updateJob?.cancel()
|
|
60
|
+
updateJob = launch {
|
|
61
|
+
delay(50)
|
|
62
|
+
fragmentModule?.closeCustomFragment()
|
|
63
|
+
fragmentModule?.showCustomFragment(
|
|
64
|
+
videoId!!,
|
|
65
|
+
accessToken!!,
|
|
66
|
+
enableDownload,
|
|
67
|
+
autoPlay ?: true
|
|
68
|
+
)
|
|
69
|
+
}
|
|
44
70
|
}
|
|
45
71
|
}
|
|
46
72
|
|
|
47
73
|
override fun onDetachedFromWindow() {
|
|
48
74
|
super.onDetachedFromWindow()
|
|
75
|
+
coroutineContext.cancel()
|
|
49
76
|
fragmentModule?.closeCustomFragment()
|
|
50
77
|
}
|
|
51
78
|
|
|
@@ -21,6 +21,17 @@ class TpStreamsPlayerViewManager : SimpleViewManager<TpStreamsPlayerView>() {
|
|
|
21
21
|
fun setAccessToken(view: TpStreamsPlayerView, accessToken: String?) {
|
|
22
22
|
accessToken?.let { view.setAccessToken(it) }
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
@ReactProp(name = "enableDownload")
|
|
26
|
+
fun setEnableDownload(view: TpStreamsPlayerView, enableDownload: Boolean?) {
|
|
27
|
+
view.setEnableDownload(enableDownload)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@ReactProp(name = "autoPlay")
|
|
31
|
+
fun setAutoPlay(view: TpStreamsPlayerView, autoPlay: Boolean?) {
|
|
32
|
+
view.setAutoPlay(autoPlay)
|
|
33
|
+
}
|
|
34
|
+
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
|
|
@@ -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,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,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
|
|
@@ -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,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,KAAK,CAAC,EAAE,OAAO,cAAc,EAAE,SAAS,CAAC;CAC1C,CAAC"}
|
package/package.json
CHANGED