react-native-tpstreams 0.1.1 → 0.1.3
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 +24 -17
- package/android/src/main/java/com/tpstreams/PlayerFragment.kt +7 -2
- package/android/src/main/java/com/tpstreams/TpStreamsPlayerView.kt +13 -1
- 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
|
|
|
@@ -65,24 +67,29 @@ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
|
|
|
65
67
|
|
|
66
68
|
@ReactMethod
|
|
67
69
|
fun closeCustomFragment() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
Log.e("FragmentModule", "closeCustomFragment() called")
|
|
71
|
+
|
|
72
|
+
// Ensure currentActivity is a FragmentActivity
|
|
73
|
+
val activity = currentActivity as? FragmentActivity
|
|
74
|
+
if (activity == null || activity.isFinishing || activity.isDestroyed) {
|
|
75
|
+
Log.e("FragmentModule", "Activity is null, finishing, or destroyed")
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
val fragmentManager = activity.supportFragmentManager
|
|
80
|
+
val playerFragment = fragmentManager.findFragmentByTag("PLAYER_FRAGMENT") as? PlayerFragment
|
|
81
|
+
|
|
82
|
+
if (playerFragment != null) {
|
|
83
|
+
Log.d("FragmentModule", "Removing PlayerFragment")
|
|
84
|
+
fragmentManager.beginTransaction()
|
|
85
|
+
.remove(playerFragment)
|
|
86
|
+
.commitAllowingStateLoss() // Avoid IllegalStateException
|
|
87
|
+
} else if (fragmentManager.backStackEntryCount > 0) {
|
|
88
|
+
Log.d("FragmentModule", "Popping back stack")
|
|
89
|
+
fragmentManager.popBackStack()
|
|
79
90
|
} else {
|
|
80
|
-
|
|
91
|
+
Log.e("FragmentModule", "No fragments to remove")
|
|
81
92
|
}
|
|
82
|
-
} ?: run {
|
|
83
|
-
// Handle the error if the activity is not a FragmentActivity
|
|
84
|
-
Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
|
|
85
|
-
}
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
@ReactMethod
|
|
@@ -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
|
}
|
|
@@ -14,6 +14,8 @@ class TpStreamsPlayerView @JvmOverloads constructor(
|
|
|
14
14
|
|
|
15
15
|
private var videoId: String? = null
|
|
16
16
|
private var accessToken: String? = null
|
|
17
|
+
private var enableDownload: Boolean = true
|
|
18
|
+
private var autoPlay :Boolean = true
|
|
17
19
|
private var fragmentModule: FragmentModule? = null
|
|
18
20
|
|
|
19
21
|
init {
|
|
@@ -37,10 +39,20 @@ class TpStreamsPlayerView @JvmOverloads constructor(
|
|
|
37
39
|
updateFragment()
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
fun setEnableDownload(enableDownload: Boolean?) {
|
|
43
|
+
this.enableDownload = enableDownload ?: true
|
|
44
|
+
updateFragment()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fun setAutoPlay(autoPlay: Boolean?) {
|
|
48
|
+
this.autoPlay = autoPlay ?: true
|
|
49
|
+
updateFragment()
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
private fun updateFragment() {
|
|
41
53
|
if (!videoId.isNullOrEmpty() && !accessToken.isNullOrEmpty()) {
|
|
42
54
|
fragmentModule?.closeCustomFragment()
|
|
43
|
-
fragmentModule?.showCustomFragment(videoId!!, accessToken
|
|
55
|
+
fragmentModule?.showCustomFragment(videoId!!, accessToken!!, enableDownload, autoPlay)
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
|
|
@@ -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