react-native-spalla-player 0.14.0 → 0.14.1
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.
|
@@ -14,186 +14,237 @@ import com.spalla.sdk.android.core.player.view.SpallaPlayerView
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class SpallaPlayerModule(reactContext: ReactApplicationContext) :
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
throw ClassCastException(
|
|
52
|
-
"Cannot play: view with tag #$tag is not a SpallaPlayerView"
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
17
|
+
ReactContextBaseJavaModule(reactContext),
|
|
18
|
+
LifecycleEventListener {
|
|
19
|
+
private val _reactContext: ReactApplicationContext
|
|
20
|
+
|
|
21
|
+
init {
|
|
22
|
+
reactContext.addLifecycleEventListener(this)
|
|
23
|
+
_reactContext = reactContext
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun getName(): String {
|
|
27
|
+
return "RNSpallaPlayer"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun onHostResume() {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
override fun onHostPause() {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun onHostDestroy() {
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@ReactMethod
|
|
41
|
+
fun play(tag: Int) {
|
|
42
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
43
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
44
|
+
if (uiManager is UIManager) {
|
|
45
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
46
|
+
if (view is SpallaPlayerContainerView) {
|
|
47
|
+
view.post {
|
|
48
|
+
view.spallaPlayerView.play()
|
|
56
49
|
}
|
|
50
|
+
} else {
|
|
51
|
+
throw ClassCastException(
|
|
52
|
+
"Cannot play: view with tag #$tag is not a SpallaPlayerView"
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
val uiManager: UIManagerModule? =
|
|
59
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)
|
|
60
|
+
uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
61
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
62
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
63
|
+
playerView.spallaPlayerView.play()
|
|
57
64
|
} else {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} else {
|
|
65
|
-
throw ClassCastException(
|
|
66
|
-
String.format(
|
|
67
|
-
"Cannot play: view with tag #%d is not a SpallaPlayerView",
|
|
68
|
-
tag
|
|
69
|
-
)
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
65
|
+
throw ClassCastException(
|
|
66
|
+
String.format(
|
|
67
|
+
"Cannot play: view with tag #%d is not a SpallaPlayerView",
|
|
68
|
+
tag
|
|
69
|
+
)
|
|
70
|
+
)
|
|
73
71
|
}
|
|
72
|
+
}
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} else {
|
|
87
|
-
throw ClassCastException(
|
|
88
|
-
"Cannot pause: view with tag #$tag is not a SpallaPlayerView"
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactMethod
|
|
77
|
+
fun pause(tag: Int) {
|
|
78
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
79
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
80
|
+
if (uiManager is UIManager) {
|
|
81
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
82
|
+
if (view is SpallaPlayerContainerView) {
|
|
83
|
+
view.post {
|
|
84
|
+
view.spallaPlayerView.pause()
|
|
92
85
|
}
|
|
86
|
+
} else {
|
|
87
|
+
throw ClassCastException(
|
|
88
|
+
"Cannot pause: view with tag #$tag is not a SpallaPlayerView"
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
val uiManager: UIManagerModule? =
|
|
95
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)
|
|
96
|
+
uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
97
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
98
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
99
|
+
playerView.spallaPlayerView.pause()
|
|
93
100
|
} else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
} else {
|
|
101
|
-
throw ClassCastException(
|
|
102
|
-
String.format(
|
|
103
|
-
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
104
|
-
tag
|
|
105
|
-
)
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
101
|
+
throw ClassCastException(
|
|
102
|
+
String.format(
|
|
103
|
+
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
104
|
+
tag
|
|
105
|
+
)
|
|
106
|
+
)
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
}
|
|
112
109
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
125
|
-
tag
|
|
126
|
-
)
|
|
127
|
-
)
|
|
128
|
-
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@ReactMethod
|
|
113
|
+
fun seekTo(tag: Int, time: Double) {
|
|
114
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
115
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
116
|
+
if (uiManager is UIManager) {
|
|
117
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
118
|
+
if (view is SpallaPlayerContainerView) {
|
|
119
|
+
view.post {
|
|
120
|
+
view.spallaPlayerView.seekTo(time)
|
|
129
121
|
}
|
|
122
|
+
} else {
|
|
123
|
+
throw ClassCastException(
|
|
124
|
+
"Cannot play: view with tag #$tag is not a SpallaPlayerView"
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)!!
|
|
131
|
+
.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
132
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
133
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
134
|
+
playerView.spallaPlayerView.seekTo(time)
|
|
135
|
+
} else {
|
|
136
|
+
throw ClassCastException(
|
|
137
|
+
String.format(
|
|
138
|
+
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
139
|
+
tag
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
130
144
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
tag
|
|
144
|
-
)
|
|
145
|
-
)
|
|
146
|
-
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@ReactMethod
|
|
148
|
+
fun selectSubtitle(tag: Int, subtitle: String?) {
|
|
149
|
+
|
|
150
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
151
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
152
|
+
if (uiManager is UIManager) {
|
|
153
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
154
|
+
if (view is SpallaPlayerContainerView) {
|
|
155
|
+
view.post {
|
|
156
|
+
view.spallaPlayerView.selectSubtitle(subtitle)
|
|
147
157
|
}
|
|
158
|
+
} else {
|
|
159
|
+
throw ClassCastException(
|
|
160
|
+
"Cannot play: view with tag #$tag is not a SpallaPlayerView"
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
|
|
167
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)!!
|
|
168
|
+
.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
169
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
170
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
171
|
+
playerView.spallaPlayerView.selectSubtitle(subtitle)
|
|
172
|
+
} else {
|
|
173
|
+
throw ClassCastException(
|
|
174
|
+
String.format(
|
|
175
|
+
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
176
|
+
tag
|
|
177
|
+
)
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
148
181
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
tag
|
|
162
|
-
)
|
|
163
|
-
)
|
|
164
|
-
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@ReactMethod
|
|
185
|
+
fun selectPlaybackRate(tag: Int, rate: Double) {
|
|
186
|
+
|
|
187
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
188
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
189
|
+
if (uiManager is UIManager) {
|
|
190
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
191
|
+
if (view is SpallaPlayerContainerView) {
|
|
192
|
+
view.post {
|
|
193
|
+
view.spallaPlayerView.play()
|
|
165
194
|
}
|
|
195
|
+
} else {
|
|
196
|
+
throw ClassCastException(
|
|
197
|
+
"Cannot play: view with tag #$tag is not a SpallaPlayerView"
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)!!
|
|
204
|
+
.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
205
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
206
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
207
|
+
playerView.spallaPlayerView.selectPlaybackRate(rate)
|
|
208
|
+
} else {
|
|
209
|
+
throw ClassCastException(
|
|
210
|
+
String.format(
|
|
211
|
+
"Cannot play: view with tag #%d is not a SpallaPplayerView",
|
|
212
|
+
tag
|
|
213
|
+
)
|
|
214
|
+
)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
166
217
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} else {
|
|
182
|
-
val uiManager: UIManagerModule? =
|
|
183
|
-
_reactContext.getNativeModule(UIManagerModule::class.java)
|
|
184
|
-
uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
185
|
-
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
186
|
-
if (playerView is SpallaPlayerContainerView) {
|
|
187
|
-
playerView.spallaPlayerView.pause()
|
|
188
|
-
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@ReactMethod
|
|
221
|
+
fun unmount(tag: Int) {
|
|
222
|
+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
|
223
|
+
val uiManager = UIManagerHelper.getUIManager(_reactContext, UIManagerType.FABRIC)
|
|
224
|
+
if (uiManager is UIManager) {
|
|
225
|
+
uiManager.resolveView(tag)?.let { view ->
|
|
226
|
+
if (view is SpallaPlayerContainerView) {
|
|
227
|
+
view.post {
|
|
228
|
+
view.spallaPlayerView.pause()
|
|
189
229
|
}
|
|
230
|
+
}
|
|
190
231
|
}
|
|
232
|
+
}
|
|
233
|
+
} else {
|
|
234
|
+
val uiManager: UIManagerModule? =
|
|
235
|
+
_reactContext.getNativeModule(UIManagerModule::class.java)
|
|
236
|
+
uiManager?.prependUIBlock { nativeViewHierarchyManager: NativeViewHierarchyManager ->
|
|
237
|
+
val playerView = nativeViewHierarchyManager.resolveView(tag)
|
|
238
|
+
if (playerView is SpallaPlayerContainerView) {
|
|
239
|
+
playerView.spallaPlayerView.pause()
|
|
240
|
+
}
|
|
241
|
+
}
|
|
191
242
|
}
|
|
243
|
+
}
|
|
192
244
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
245
|
+
@ReactMethod
|
|
246
|
+
fun initialize(token: String, applicationId: String?) {
|
|
247
|
+
SpallaSDK.initialize(_reactContext, token)
|
|
248
|
+
}
|
|
198
249
|
|
|
199
250
|
}
|