[Android] Fix activity resolving for the MediaPlayer
Nicolas Pomepuy
git at videolan.org
Wed Jan 5 14:31:07 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Dec 21 12:17:07 2021 +0100| [079d2024bfd92612a785d8bc2c7089660619e5d8] | committer: Nicolas Pomepuy
Fix activity resolving for the MediaPlayer
Fixes #2274
> https://code.videolan.org/videolan/vlc-android/commit/079d2024bfd92612a785d8bc2c7089660619e5d8
---
libvlc/src/org/videolan/libvlc/VideoHelper.java | 2 +-
libvlc/src/org/videolan/libvlc/util/AndroidUtil.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/libvlc/src/org/videolan/libvlc/VideoHelper.java b/libvlc/src/org/videolan/libvlc/VideoHelper.java
index dc6782459..1647ef332 100644
--- a/libvlc/src/org/videolan/libvlc/VideoHelper.java
+++ b/libvlc/src/org/videolan/libvlc/VideoHelper.java
@@ -190,7 +190,7 @@ class VideoHelper implements IVLCVout.OnNewVideoLayoutListener {
void updateVideoSurfaces() {
if (mMediaPlayer == null || mMediaPlayer.isReleased() || !mMediaPlayer.getVLCVout().areViewsAttached()) return;
final boolean isPrimary = mDisplayManager == null || mDisplayManager.isPrimary();
- final Activity activity = isPrimary && mVideoSurfaceFrame.getContext() instanceof Activity ? (Activity) mVideoSurfaceFrame.getContext() : null;
+ final Activity activity = !isPrimary ? null : AndroidUtil.resolveActivity(mVideoSurfaceFrame.getContext());
int sw;
int sh;
diff --git a/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java b/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
index 81cb2c4fc..6f91666af 100644
--- a/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
+++ b/libvlc/src/org/videolan/libvlc/util/AndroidUtil.java
@@ -20,6 +20,9 @@
package org.videolan.libvlc.util;
+import android.app.Activity;
+import android.content.Context;
+import android.content.ContextWrapper;
import android.net.Uri;
import android.os.Build;
@@ -60,4 +63,11 @@ public class AndroidUtil {
public static Uri FileToUri(File file) {
return Uri.fromFile(file);
}
+
+ public static Activity resolveActivity(Context context) {
+ if (context instanceof Activity) return (Activity) context;
+ if (context instanceof ContextWrapper) return resolveActivity(((ContextWrapper)context).getBaseContext());
+ return null;
+
+ }
}
\ No newline at end of file
More information about the Android
mailing list