mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-21 08:41:57 +00:00
Merge pull request #391 from saifshaikh1805/patch-issue301
fix: issue #301
This commit is contained in:
commit
14e8e90ee3
1 changed files with 22 additions and 0 deletions
|
|
@ -8,6 +8,9 @@ import android.view.Surface
|
||||||
import android.view.TextureView
|
import android.view.TextureView
|
||||||
import dev.jdtech.mpv.MPVLib
|
import dev.jdtech.mpv.MPVLib
|
||||||
|
|
||||||
|
import com.facebook.react.bridge.LifecycleEventListener
|
||||||
|
import com.facebook.react.bridge.ReactContext
|
||||||
|
|
||||||
class MPVView @JvmOverloads constructor(
|
class MPVView @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
|
|
@ -40,9 +43,27 @@ class MPVView @JvmOverloads constructor(
|
||||||
var onErrorCallback: ((message: String) -> Unit)? = null
|
var onErrorCallback: ((message: String) -> Unit)? = null
|
||||||
var onTracksChangedCallback: ((audioTracks: List<Map<String, Any>>, subtitleTracks: List<Map<String, Any>>) -> Unit)? = null
|
var onTracksChangedCallback: ((audioTracks: List<Map<String, Any>>, subtitleTracks: List<Map<String, Any>>) -> Unit)? = null
|
||||||
|
|
||||||
|
private var resumeOnForeground = false
|
||||||
|
private val lifeCycleListener = object : LifecycleEventListener {
|
||||||
|
override fun onHostPause() {
|
||||||
|
resumeOnForeground = !isPaused;
|
||||||
|
if(resumeOnForeground) {
|
||||||
|
Log.d(TAG, "App backgrounded — pausing MPV")
|
||||||
|
setPaused(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onHostResume() {
|
||||||
|
if(resumeOnForeground) {
|
||||||
|
setPaused(false)
|
||||||
|
resumeOnForeground = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
override fun onHostDestroy() {}
|
||||||
|
}
|
||||||
init {
|
init {
|
||||||
surfaceTextureListener = this
|
surfaceTextureListener = this
|
||||||
isOpaque = false
|
isOpaque = false
|
||||||
|
(context as? ReactContext)?.addLifecycleEventListener(lifeCycleListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureAvailable(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
|
override fun onSurfaceTextureAvailable(surfaceTexture: SurfaceTexture, width: Int, height: Int) {
|
||||||
|
|
@ -80,6 +101,7 @@ class MPVView @JvmOverloads constructor(
|
||||||
|
|
||||||
override fun onSurfaceTextureDestroyed(surfaceTexture: SurfaceTexture): Boolean {
|
override fun onSurfaceTextureDestroyed(surfaceTexture: SurfaceTexture): Boolean {
|
||||||
Log.d(TAG, "Surface texture destroyed")
|
Log.d(TAG, "Surface texture destroyed")
|
||||||
|
(context as? ReactContext)?.removeLifecycleEventListener(lifeCycleListener)
|
||||||
if (isMpvInitialized) {
|
if (isMpvInitialized) {
|
||||||
MPVLib.removeObserver(this)
|
MPVLib.removeObserver(this)
|
||||||
MPVLib.detachSurface()
|
MPVLib.detachSurface()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue