expo-mpv 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,14 +1,12 @@
1
1
  package expo.modules.mpv
2
2
 
3
- import android.app.Activity
4
- import android.app.Application
5
3
  import android.content.Context
6
4
  import android.os.Build
7
- import android.os.Bundle
8
5
  import android.os.Handler
9
6
  import android.os.Looper
10
7
  import android.view.SurfaceHolder
11
8
  import android.view.SurfaceView
9
+ import android.view.View
12
10
  import expo.modules.kotlin.AppContext
13
11
  import expo.modules.kotlin.viewevent.EventDispatcher
14
12
  import expo.modules.kotlin.views.ExpoView
@@ -86,49 +84,36 @@ class ExpoMpvView(context: Context, appContext: AppContext) : ExpoView(context,
86
84
  }
87
85
  }
88
86
  })
89
-
90
- setupLifecycle()
91
87
  }
92
88
 
93
- // MARK: - Lifecycle
89
+ override fun onDetachedFromWindow() {
90
+ super.onDetachedFromWindow()
91
+ destroy()
92
+ }
94
93
 
95
- private val lifecycleCallbacks = object : Application.ActivityLifecycleCallbacks {
96
- override fun onActivityPaused(activity: Activity) {
97
- if (nativePtr != 0L && isInitialized && activity == appContext.currentActivity) {
94
+ override fun onWindowVisibilityChanged(visibility: Int) {
95
+ super.onWindowVisibilityChanged(visibility)
96
+ if (nativePtr != 0L && isInitialized) {
97
+ if (visibility == View.GONE || visibility == View.INVISIBLE) {
98
98
  setPropertyString("vid", "no")
99
- }
100
- }
101
- override fun onActivityResumed(activity: Activity) {
102
- if (nativePtr != 0L && isInitialized && activity == appContext.currentActivity) {
99
+ } else {
103
100
  setPropertyString("vid", "auto")
104
101
  }
105
102
  }
106
- override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
107
- override fun onActivityStarted(activity: Activity) {}
108
- override fun onActivityStopped(activity: Activity) {}
109
- override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
110
- override fun onActivityDestroyed(activity: Activity) {}
111
- }
112
-
113
- private fun setupLifecycle() {
114
- val app = context.applicationContext as? Application ?: return
115
- app.registerActivityLifecycleCallbacks(lifecycleCallbacks)
116
- }
117
-
118
- override fun onDetachedFromWindow() {
119
- super.onDetachedFromWindow()
120
- destroy()
121
103
  }
122
104
 
123
105
  fun destroy() {
124
106
  stopProgressTimer()
125
- val app = context.applicationContext as? Application
126
- app?.unregisterActivityLifecycleCallbacks(lifecycleCallbacks)
127
- if (nativePtr != 0L) {
128
- MPVLib.nativeDestroy(nativePtr)
129
- nativePtr = 0
130
- }
107
+ val ptr = nativePtr
108
+ nativePtr = 0
131
109
  isInitialized = false
110
+ if (ptr != 0L) {
111
+ // Destroy on background thread to avoid blocking the main thread
112
+ // (pthread_join + mpv_terminate_destroy can take seconds)
113
+ Thread {
114
+ MPVLib.nativeDestroy(ptr)
115
+ }.start()
116
+ }
132
117
  }
133
118
 
134
119
  // MARK: - MPV Setup (two-phase: create+options, then initialize after surface)
@@ -154,6 +139,12 @@ class ExpoMpvView(context: Context, appContext: AppContext) : ExpoView(context,
154
139
  android.util.Log.w("ExpoMpv", "Emulator detected, hardware decoding disabled (using software decoding)")
155
140
  }
156
141
 
142
+ // Network stream caching
143
+ MPVLib.nativeSetOptionString(nativePtr, "cache", "yes")
144
+ MPVLib.nativeSetOptionString(nativePtr, "demuxer-max-bytes", "150M")
145
+ MPVLib.nativeSetOptionString(nativePtr, "demuxer-max-back-bytes", "50M")
146
+ MPVLib.nativeSetOptionString(nativePtr, "cache-pause", "yes")
147
+
157
148
  // General
158
149
  MPVLib.nativeSetOptionString(nativePtr, "force-window", "yes")
159
150
  MPVLib.nativeSetOptionString(nativePtr, "keep-open", "yes")
@@ -461,8 +461,12 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void * /*reserved*/) {
461
461
  auto fn = (av_jni_set_java_vm_fn)dlsym(avcodec, "av_jni_set_java_vm");
462
462
  if (fn) {
463
463
  fn(vm, nullptr);
464
- LOGI("av_jni_set_java_vm set");
464
+ LOGI("av_jni_set_java_vm set — MediaCodec hardware decoding available");
465
+ } else {
466
+ LOGE("av_jni_set_java_vm symbol not found in libavcodec.so — MediaCodec hwdec may not work");
465
467
  }
468
+ } else {
469
+ LOGE("Failed to dlopen libavcodec.so — MediaCodec hardware decoding unavailable");
466
470
  }
467
471
 
468
472
  jclass cls = env->FindClass("expo/modules/mpv/MPVLib");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-mpv",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Expo module wrapping libmpv for video playback on iOS and Android",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",