react-native-tpstreams 0.1.6 → 0.1.7

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.
@@ -1,190 +1,190 @@
1
- package com.tpstreams
2
-
3
- import android.content.Context
4
- import android.os.Bundle
5
- import androidx.fragment.app.FragmentActivity
6
- import com.facebook.react.bridge.ReactMethod
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule
8
- import com.facebook.react.bridge.ReactApplicationContext
9
- import android.util.Log
10
- import androidx.lifecycle.LiveData
11
- import androidx.lifecycle.ViewModel
12
- import androidx.lifecycle.ViewModelProvider
13
- import com.facebook.react.bridge.Arguments
14
- import com.facebook.react.bridge.WritableMap
15
- import com.facebook.react.modules.core.DeviceEventManagerModule
16
- import com.tpstream.player.data.Asset
17
- import com.tpstream.player.offline.TpStreamDownloadManager
18
- import com.tpstream.player.TPStreamsSDK
19
-
20
- class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
21
-
22
- lateinit var viewModel: DownloadListViewModel
23
- private var assets = listOf<Asset>()
24
-
25
- override fun initialize() {
26
- super.initialize()
27
- (currentActivity as? FragmentActivity)?.let {
28
- viewModel = DownloadListViewModel.init(it)
29
- }
30
- Log.d("FragmentModule", "initialize: ")
31
- }
32
-
33
- override fun getName(): String {
34
- return "FragmentModule"
35
- }
36
-
37
- @ReactMethod
38
- fun showCustomFragment(videoId: String, accessToken: String, enableDownload: Boolean, autoPlay: Boolean) {
39
- Log.e("FragmentModule", "showCustomFragment() called")
40
- // Ensure the currentActivity is a FragmentActivity
41
- val activity = currentActivity as? FragmentActivity
42
- activity?.let {
43
- // Begin the fragment transaction
44
- val fragmentTransaction = it.supportFragmentManager.beginTransaction()
45
-
46
- // Create a new fragment instance
47
- val bundle = Bundle()
48
- bundle.putString("VIDEO_ID", videoId)
49
- bundle.putString("ACCESS_TOKEN", accessToken)
50
- bundle.putBoolean("ENABLE_DOWNLOAD_SUPPORT", enableDownload)
51
- bundle.putBoolean("AUTO_PLAY", autoPlay)
52
- val fragment = PlayerFragment()
53
- fragment.setArguments(bundle)
54
-
55
- // Find a container to add the fragment
56
- val fragmentContainerId = android.R.id.content // or you could specify your own container ID
57
-
58
- // Add the fragment
59
- fragmentTransaction.replace(fragmentContainerId, fragment)
60
- fragmentTransaction.addToBackStack(null) // Optional: Add fragment to back stack
61
- fragmentTransaction.commit()
62
- } ?: run {
63
- // Handle the error if the activity is not a FragmentActivity
64
- Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
65
- }
66
- }
67
-
68
- @ReactMethod
69
- fun closeCustomFragment() {
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()
90
- } else {
91
- Log.e("FragmentModule", "No fragments to remove")
92
- }
93
- }
94
-
95
- @ReactMethod
96
- fun observeDownloadData() {
97
- // Ensure this code runs on the main thread
98
- currentActivity?.runOnUiThread {
99
- val activity = currentActivity as? FragmentActivity
100
- activity?.let {
101
- // Observe LiveData only on the main thread
102
- viewModel.getDownloadData().observe(it) { assets ->
103
- this.assets = assets ?: emptyList()
104
- // Emit event to React Native
105
- val eventMap = Arguments.createMap()
106
- val assetsList = Arguments.createArray()
107
-
108
- assets?.forEachIndexed { index , asset ->
109
- val assetMap = Arguments.createMap()
110
- assetMap.putString("id", index.toString())
111
- assetMap.putString("videoId", asset.id)
112
- assetMap.putString("title", asset.title)
113
- assetMap.putString("percentage", asset.video.percentageDownloaded.toString())
114
- assetMap.putString("status", asset.video.downloadState?.name ?: "Unknown")
115
- assetMap.putString("duration", asset.video.duration.toString())
116
-
117
- assetsList.pushMap(assetMap)
118
- }
119
-
120
- eventMap.putArray("assets", assetsList)
121
- reactApplicationContext
122
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
123
- .emit("onDownloadDataChanged", eventMap)
124
- }
125
- } ?: run {
126
- Log.e("FragmentModule", "Current activity is not a FragmentActivity")
127
- }
128
- }
129
- }
130
-
131
- @ReactMethod
132
- fun pauseDownload(videoId: String) {
133
- val asset = assets.first { it.id == videoId }
134
- viewModel.pauseDownload(asset)
135
- }
136
-
137
- @ReactMethod
138
- fun resumeDownload(videoId: String) {
139
- val asset = assets.first { it.id == videoId }
140
- viewModel.resumeDownload(asset)
141
- }
142
-
143
- @ReactMethod
144
- fun cancelDownload(videoId: String) {
145
- val asset = assets.first { it.id == videoId }
146
- viewModel.cancelDownload(asset)
147
- }
148
-
149
- @ReactMethod
150
- fun deleteDownload(videoId: String) {
151
- val asset = assets.first { it.id == videoId }
152
- viewModel.deleteDownload(asset)
153
- }
154
-
155
- }
156
-
157
- class DownloadListViewModel(context: Context): ViewModel() {
158
-
159
- private var tpStreamDownloadManager: TpStreamDownloadManager = TpStreamDownloadManager(context)
160
-
161
- fun getDownloadData(): LiveData<List<Asset>?> {
162
- return tpStreamDownloadManager.getAllDownloads()
163
- }
164
-
165
- fun pauseDownload(offlineAssetInfo: Asset) {
166
- tpStreamDownloadManager.pauseDownload(offlineAssetInfo)
167
- }
168
-
169
- fun resumeDownload(offlineAssetInfo: Asset) {
170
- tpStreamDownloadManager.resumeDownload(offlineAssetInfo)
171
- }
172
-
173
- fun cancelDownload(offlineAssetInfo: Asset) {
174
- tpStreamDownloadManager.cancelDownload(offlineAssetInfo)
175
- }
176
-
177
- fun deleteDownload(offlineAssetInfo: Asset) {
178
- tpStreamDownloadManager.deleteDownload(offlineAssetInfo)
179
- }
180
-
181
- companion object {
182
- fun init(fragmentActivity: FragmentActivity) : DownloadListViewModel {
183
- return ViewModelProvider(fragmentActivity, object : ViewModelProvider.Factory {
184
- override fun <T : ViewModel> create(modelClass: Class<T>): T {
185
- return DownloadListViewModel(fragmentActivity) as T
186
- }
187
- })[DownloadListViewModel::class.java]
188
- }
189
- }
190
- }
1
+ package com.tpstreams
2
+
3
+ import android.content.Context
4
+ import android.os.Bundle
5
+ import androidx.fragment.app.FragmentActivity
6
+ import com.facebook.react.bridge.ReactMethod
7
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
8
+ import com.facebook.react.bridge.ReactApplicationContext
9
+ import android.util.Log
10
+ import androidx.lifecycle.LiveData
11
+ import androidx.lifecycle.ViewModel
12
+ import androidx.lifecycle.ViewModelProvider
13
+ import com.facebook.react.bridge.Arguments
14
+ import com.facebook.react.bridge.WritableMap
15
+ import com.facebook.react.modules.core.DeviceEventManagerModule
16
+ import com.tpstream.player.data.Asset
17
+ import com.tpstream.player.offline.TpStreamDownloadManager
18
+ import com.tpstream.player.TPStreamsSDK
19
+
20
+ class FragmentModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
21
+
22
+ lateinit var viewModel: DownloadListViewModel
23
+ private var assets = listOf<Asset>()
24
+
25
+ override fun initialize() {
26
+ super.initialize()
27
+ (currentActivity as? FragmentActivity)?.let {
28
+ viewModel = DownloadListViewModel.init(it)
29
+ }
30
+ Log.d("FragmentModule", "initialize: ")
31
+ }
32
+
33
+ override fun getName(): String {
34
+ return "FragmentModule"
35
+ }
36
+
37
+ @ReactMethod
38
+ fun showCustomFragment(videoId: String, accessToken: String, enableDownload: Boolean, autoPlay: Boolean) {
39
+ Log.e("FragmentModule", "showCustomFragment() called")
40
+ // Ensure the currentActivity is a FragmentActivity
41
+ val activity = currentActivity as? FragmentActivity
42
+ activity?.let {
43
+ // Begin the fragment transaction
44
+ val fragmentTransaction = it.supportFragmentManager.beginTransaction()
45
+
46
+ // Create a new fragment instance
47
+ val bundle = Bundle()
48
+ bundle.putString("VIDEO_ID", videoId)
49
+ bundle.putString("ACCESS_TOKEN", accessToken)
50
+ bundle.putBoolean("ENABLE_DOWNLOAD_SUPPORT", enableDownload)
51
+ bundle.putBoolean("AUTO_PLAY", autoPlay)
52
+ val fragment = PlayerFragment()
53
+ fragment.setArguments(bundle)
54
+
55
+ // Find a container to add the fragment
56
+ val fragmentContainerId = android.R.id.content // or you could specify your own container ID
57
+
58
+ // Add the fragment
59
+ fragmentTransaction.replace(fragmentContainerId, fragment)
60
+ fragmentTransaction.addToBackStack(null) // Optional: Add fragment to back stack
61
+ fragmentTransaction.commit()
62
+ } ?: run {
63
+ // Handle the error if the activity is not a FragmentActivity
64
+ Log.e("ReactNativeJS", "Current activity is not a FragmentActivity")
65
+ }
66
+ }
67
+
68
+ @ReactMethod
69
+ fun closeCustomFragment() {
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()
90
+ } else {
91
+ Log.e("FragmentModule", "No fragments to remove")
92
+ }
93
+ }
94
+
95
+ @ReactMethod
96
+ fun observeDownloadData() {
97
+ // Ensure this code runs on the main thread
98
+ currentActivity?.runOnUiThread {
99
+ val activity = currentActivity as? FragmentActivity
100
+ activity?.let {
101
+ // Observe LiveData only on the main thread
102
+ viewModel.getDownloadData().observe(it) { assets ->
103
+ this.assets = assets ?: emptyList()
104
+ // Emit event to React Native
105
+ val eventMap = Arguments.createMap()
106
+ val assetsList = Arguments.createArray()
107
+
108
+ assets?.forEachIndexed { index , asset ->
109
+ val assetMap = Arguments.createMap()
110
+ assetMap.putString("id", index.toString())
111
+ assetMap.putString("videoId", asset.id)
112
+ assetMap.putString("title", asset.title)
113
+ assetMap.putString("percentage", asset.video.percentageDownloaded.toString())
114
+ assetMap.putString("status", asset.video.downloadState?.name ?: "Unknown")
115
+ assetMap.putString("duration", asset.video.duration.toString())
116
+
117
+ assetsList.pushMap(assetMap)
118
+ }
119
+
120
+ eventMap.putArray("assets", assetsList)
121
+ reactApplicationContext
122
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
123
+ .emit("onDownloadDataChanged", eventMap)
124
+ }
125
+ } ?: run {
126
+ Log.e("FragmentModule", "Current activity is not a FragmentActivity")
127
+ }
128
+ }
129
+ }
130
+
131
+ @ReactMethod
132
+ fun pauseDownload(videoId: String) {
133
+ val asset = assets.first { it.id == videoId }
134
+ viewModel.pauseDownload(asset)
135
+ }
136
+
137
+ @ReactMethod
138
+ fun resumeDownload(videoId: String) {
139
+ val asset = assets.first { it.id == videoId }
140
+ viewModel.resumeDownload(asset)
141
+ }
142
+
143
+ @ReactMethod
144
+ fun cancelDownload(videoId: String) {
145
+ val asset = assets.first { it.id == videoId }
146
+ viewModel.cancelDownload(asset)
147
+ }
148
+
149
+ @ReactMethod
150
+ fun deleteDownload(videoId: String) {
151
+ val asset = assets.first { it.id == videoId }
152
+ viewModel.deleteDownload(asset)
153
+ }
154
+
155
+ }
156
+
157
+ class DownloadListViewModel(context: Context): ViewModel() {
158
+
159
+ private var tpStreamDownloadManager: TpStreamDownloadManager = TpStreamDownloadManager(context)
160
+
161
+ fun getDownloadData(): LiveData<List<Asset>?> {
162
+ return tpStreamDownloadManager.getAllDownloads()
163
+ }
164
+
165
+ fun pauseDownload(offlineAssetInfo: Asset) {
166
+ tpStreamDownloadManager.pauseDownload(offlineAssetInfo)
167
+ }
168
+
169
+ fun resumeDownload(offlineAssetInfo: Asset) {
170
+ tpStreamDownloadManager.resumeDownload(offlineAssetInfo)
171
+ }
172
+
173
+ fun cancelDownload(offlineAssetInfo: Asset) {
174
+ tpStreamDownloadManager.cancelDownload(offlineAssetInfo)
175
+ }
176
+
177
+ fun deleteDownload(offlineAssetInfo: Asset) {
178
+ tpStreamDownloadManager.deleteDownload(offlineAssetInfo)
179
+ }
180
+
181
+ companion object {
182
+ fun init(fragmentActivity: FragmentActivity) : DownloadListViewModel {
183
+ return ViewModelProvider(fragmentActivity, object : ViewModelProvider.Factory {
184
+ override fun <T : ViewModel> create(modelClass: Class<T>): T {
185
+ return DownloadListViewModel(fragmentActivity) as T
186
+ }
187
+ })[DownloadListViewModel::class.java]
188
+ }
189
+ }
190
+ }
@@ -1,96 +1,163 @@
1
- package com.tpstreams
2
-
3
- import android.os.Bundle
4
- import android.util.Log
5
- import android.view.LayoutInflater
6
- import android.view.View
7
- import android.view.ViewGroup
8
- import android.widget.Toast
9
- import androidx.fragment.app.Fragment
10
- import com.tpstream.player.TPStreamPlayerListener
11
- import com.tpstream.player.TpInitParams
12
- import com.tpstream.player.TpStreamPlayer
13
- import com.tpstream.player.ui.InitializationListener
14
- import com.tpstream.player.ui.TPStreamPlayerView
15
- import com.tpstream.player.ui.TpStreamPlayerFragment
16
-
17
- class PlayerFragment : Fragment() {
18
-
19
- lateinit var player: TpStreamPlayer
20
- lateinit var playerView: TPStreamPlayerView
21
- lateinit var playerFragment: TpStreamPlayerFragment
22
- private var videoId :String = ""
23
- private var accessToken :String = ""
24
- private var enableDownloadSupport :Boolean = true
25
- private var setAutoPlay :Boolean = true
26
-
27
- override fun onCreate(savedInstanceState: Bundle?) {
28
- super.onCreate(savedInstanceState)
29
- val bundle = arguments
30
- if (bundle != null) {
31
- videoId = bundle.getString("VIDEO_ID") ?: ""
32
- accessToken = bundle.getString("ACCESS_TOKEN") ?: ""
33
- enableDownloadSupport = bundle.getBoolean("ENABLE_DOWNLOAD_SUPPORT", true)
34
- setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
35
-
36
- }
37
- }
38
-
39
- override fun onCreateView(
40
- inflater: LayoutInflater, container: ViewGroup?,
41
- savedInstanceState: Bundle?
42
- ): View? {
43
- return inflater.inflate(R.layout.fragment_player, container, false)
44
- }
45
-
46
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
47
- super.onViewCreated(view, savedInstanceState)
48
- playerFragment = childFragmentManager.findFragmentById(R.id.tpstream_player_fragment) as TpStreamPlayerFragment
49
- playerFragment.setOnInitializationListener(object: InitializationListener {
50
-
51
- override fun onInitializationSuccess(player: TpStreamPlayer) {
52
- this@PlayerFragment.player = player
53
- playerView = playerFragment.tpStreamPlayerView
54
- loadPLayer()
55
- addPlayerListener()
56
- }
57
- })
58
- }
59
-
60
- fun loadPLayer() {
61
- val parameters = TpInitParams.Builder()
62
- .setVideoId(videoId)
63
- .setAccessToken(accessToken)
64
- .enableDownloadSupport(enableDownloadSupport)
65
- .setAutoPlay(setAutoPlay)
66
- .build()
67
- player.load(parameters)
68
- }
69
-
70
- private fun addPlayerListener(){
71
- player.setListener( object : TPStreamPlayerListener {
72
- override fun onPlaybackStateChanged(playbackState: Int) {
73
- Log.d("TAG", "onPlaybackStateChanged: $playbackState")
74
- }
75
-
76
- override fun onAccessTokenExpired(videoId: String, callback: (String) -> Unit) {
77
- callback(accessToken)
78
- }
79
-
80
- override fun onMarkerCallback(timesInSeconds: Long) {
81
- Toast.makeText(requireContext(),"Time $timesInSeconds", Toast.LENGTH_SHORT).show()
82
- }
83
- })
84
- }
85
-
86
- override fun onResume() {
87
- super.onResume()
88
- Log.d("ReactNativeJS", "onResume: ")
89
- }
90
-
91
- override fun onDestroy() {
92
- super.onDestroy()
93
- Log.d("ReactNativeJS", "onDestroy: ")
94
- }
95
-
96
- }
1
+ package com.tpstreams
2
+
3
+ import android.os.Bundle
4
+ import android.util.Log
5
+ import android.view.LayoutInflater
6
+ import android.view.View
7
+ import android.view.ViewGroup
8
+ import android.widget.Toast
9
+ import androidx.fragment.app.Fragment
10
+ import com.tpstream.player.TPStreamPlayerListener
11
+ import com.tpstream.player.TpInitParams
12
+ import com.tpstream.player.TpStreamPlayer
13
+ import com.tpstream.player.ui.InitializationListener
14
+ import com.tpstream.player.ui.TPStreamPlayerView
15
+ import com.tpstream.player.ui.TpStreamPlayerFragment
16
+
17
+ class PlayerFragment : Fragment() {
18
+
19
+ lateinit var player: TpStreamPlayer
20
+ lateinit var playerView: TPStreamPlayerView
21
+ lateinit var playerFragment: TpStreamPlayerFragment
22
+ private var videoId :String = ""
23
+ private var accessToken :String = ""
24
+ private var enableDownloadSupport :Boolean = true
25
+ private var setAutoPlay :Boolean = true
26
+
27
+ companion object {
28
+ var instance: PlayerFragment? = null
29
+ }
30
+
31
+ override fun onCreate(savedInstanceState: Bundle?) {
32
+ super.onCreate(savedInstanceState)
33
+ val bundle = arguments
34
+ if (bundle != null) {
35
+ videoId = bundle.getString("VIDEO_ID") ?: ""
36
+ accessToken = bundle.getString("ACCESS_TOKEN") ?: ""
37
+ enableDownloadSupport = bundle.getBoolean("ENABLE_DOWNLOAD_SUPPORT", true)
38
+ setAutoPlay = bundle.getBoolean("AUTO_PLAY", true)
39
+
40
+ }
41
+ }
42
+
43
+ override fun onCreateView(
44
+ inflater: LayoutInflater, container: ViewGroup?,
45
+ savedInstanceState: Bundle?
46
+ ): View? {
47
+ return inflater.inflate(R.layout.fragment_player, container, false)
48
+ }
49
+
50
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
51
+ super.onViewCreated(view, savedInstanceState)
52
+ instance = this
53
+ playerFragment = childFragmentManager.findFragmentById(R.id.tpstream_player_fragment) as TpStreamPlayerFragment
54
+ playerFragment.setOnInitializationListener(object: InitializationListener {
55
+
56
+ override fun onInitializationSuccess(player: TpStreamPlayer) {
57
+ this@PlayerFragment.player = player
58
+ playerView = playerFragment.tpStreamPlayerView
59
+ loadPLayer()
60
+ addPlayerListener()
61
+ }
62
+ })
63
+ }
64
+
65
+ fun loadPLayer() {
66
+ val parameters = TpInitParams.Builder()
67
+ .setVideoId(videoId)
68
+ .setAccessToken(accessToken)
69
+ .enableDownloadSupport(enableDownloadSupport)
70
+ .setAutoPlay(setAutoPlay)
71
+ .build()
72
+ requireActivity().runOnUiThread {
73
+ player.load(parameters)
74
+ }
75
+ }
76
+
77
+ private fun addPlayerListener(){
78
+ player.setListener( object : TPStreamPlayerListener {
79
+ override fun onPlaybackStateChanged(playbackState: Int) {
80
+ Log.d("TAG", "onPlaybackStateChanged: $playbackState")
81
+ }
82
+
83
+ override fun onAccessTokenExpired(videoId: String, callback: (String) -> Unit) {
84
+ callback(accessToken)
85
+ }
86
+
87
+ override fun onMarkerCallback(timesInSeconds: Long) {
88
+ requireActivity().runOnUiThread {
89
+ Toast.makeText(requireContext(),"Time $timesInSeconds", Toast.LENGTH_SHORT).show()
90
+ }
91
+ }
92
+ })
93
+ }
94
+ // Core Player Controls
95
+ fun play() {
96
+ requireActivity().runOnUiThread {
97
+ player.play()
98
+ }
99
+ }
100
+
101
+ fun pause() {
102
+ requireActivity().runOnUiThread {
103
+ player.pause()
104
+ }
105
+ }
106
+
107
+ fun seekTo(position: Long) {
108
+ requireActivity().runOnUiThread {
109
+ player.seekTo(position)
110
+ }
111
+ }
112
+
113
+ fun release() {
114
+ requireActivity().runOnUiThread {
115
+ player.release()
116
+ }
117
+ }
118
+
119
+ fun load(params: TpInitParams) {
120
+ requireActivity().runOnUiThread {
121
+ player.load(params)
122
+ }
123
+ }
124
+
125
+ // Playback & State Management
126
+ fun getCurrentTime(): Double = player.getCurrentTime().toDouble()
127
+
128
+ fun getDuration(): Double = player.getDuration().toDouble()
129
+
130
+ fun getBufferedTime(): Double = player.getBufferedTime().toDouble()
131
+
132
+ fun getPlaybackState(): Int = player.getPlaybackState()
133
+
134
+ fun getPlayWhenReady(): Boolean = player.getPlayWhenReady()
135
+
136
+ fun setPlayWhenReady(playWhenReady: Boolean) {
137
+ requireActivity().runOnUiThread {
138
+ player.setPlayWhenReady(playWhenReady)
139
+ }
140
+ }
141
+
142
+
143
+ // Speed & Volume
144
+ fun getPlaybackSpeed(): Float = player.getPlayBackSpeed()
145
+
146
+ fun setPlaybackSpeed(speed: Float) {
147
+ requireActivity().runOnUiThread {
148
+ player.setPlaybackSpeed(speed)
149
+ }
150
+ }
151
+
152
+ override fun onResume() {
153
+ super.onResume()
154
+ Log.d("ReactNativeJS", "onResume: ")
155
+ }
156
+
157
+ override fun onDestroy() {
158
+ super.onDestroy()
159
+ instance = null
160
+ Log.d("ReactNativeJS", "onDestroy: ")
161
+ }
162
+
163
+ }