[Android] IVLCVout: add surface callbacks
Thomas Guillem
git at videolan.org
Tue Jul 7 11:19:14 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jul 7 11:15:25 2015 +0200| [cc459de738c5fb55261e32428b54567db4788de2] | committer: Thomas Guillem
IVLCVout: add surface callbacks
And clients can register more than one callback.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=cc459de738c5fb55261e32428b54567db4788de2
---
libvlc/src/org/videolan/libvlc/AWindow.java | 21 ++++++++++++++-----
libvlc/src/org/videolan/libvlc/IVLCVout.java | 22 ++++++++++++++++++--
.../vlc/gui/video/VideoPlayerActivity.java | 20 +++++++++++-------
3 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/AWindow.java b/libvlc/src/org/videolan/libvlc/AWindow.java
index 3389f67..ce8e193 100644
--- a/libvlc/src/org/videolan/libvlc/AWindow.java
+++ b/libvlc/src/org/videolan/libvlc/AWindow.java
@@ -34,6 +34,7 @@ import android.view.TextureView;
import org.videolan.libvlc.util.AndroidUtil;
+import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
class AWindow implements IAWindowNativeHandler, IVLCVout {
@@ -195,7 +196,7 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
private final SurfaceHelper[] mSurfaceHelpers;
private final SurfaceCallback mSurfaceCallback;
private final AtomicInteger mSurfacesState = new AtomicInteger(SURFACE_STATE_INIT);
- private IVLCVout.Callback mIAndroidWindowCallback = null;
+ private ArrayList<IVLCVout.Callback> mIVLCVoutCallbacks = new ArrayList<IVLCVout.Callback>();
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final Object mNativeLock = new Object();
/* synchronized Surfaces accessed by an other thread from JNI */
@@ -322,6 +323,8 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
}
if (mSurfaceCallback != null)
mSurfaceCallback.onSurfacesDestroyed(this);
+ for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
+ cb.onSurfacesDestroyed(this);
}
@Override
@@ -344,6 +347,8 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
mSurfacesState.set(SURFACE_STATE_READY);
if (mSurfaceCallback != null)
mSurfaceCallback.onSurfacesCreated(this);
+ for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
+ cb.onSurfacesCreated(this);
}
}
@@ -484,8 +489,14 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
}
@Override
- public void setCallback(IVLCVout.Callback callback) {
- mIAndroidWindowCallback = callback;
+ public void addCallback(IVLCVout.Callback callback) {
+ if (!mIVLCVoutCallbacks.contains(callback))
+ mIVLCVoutCallbacks.add(callback);
+ }
+
+ @Override
+ public void removeCallback(IVLCVout.Callback callback) {
+ mIVLCVoutCallbacks.remove(callback);
}
@Override
@@ -493,8 +504,8 @@ class AWindow implements IAWindowNativeHandler, IVLCVout {
mHandler.post(new Runnable() {
@Override
public void run() {
- if (mIAndroidWindowCallback != null)
- mIAndroidWindowCallback.onNewLayout(AWindow.this, width, height, visibleWidth, visibleHeight, sarNum, sarDen);
+ for (IVLCVout.Callback cb : mIVLCVoutCallbacks)
+ cb.onNewLayout(AWindow.this, width, height, visibleWidth, visibleHeight, sarNum, sarDen);
}
});
}
diff --git a/libvlc/src/org/videolan/libvlc/IVLCVout.java b/libvlc/src/org/videolan/libvlc/IVLCVout.java
index 47c54d2..01c7056 100644
--- a/libvlc/src/org/videolan/libvlc/IVLCVout.java
+++ b/libvlc/src/org/videolan/libvlc/IVLCVout.java
@@ -44,6 +44,18 @@ public interface IVLCVout {
*/
@MainThread
void onNewLayout(IVLCVout vlcVout, int width, int height, int visibleWidth, int visibleHeight, int sarNum, int sarDen);
+
+ /**
+ * This callback is called when surfaces are created.
+ */
+ @MainThread
+ void onSurfacesCreated(IVLCVout vlcVout);
+
+ /**
+ * This callback is called when surfaces are destroyed.
+ */
+ @MainThread
+ void onSurfacesDestroyed(IVLCVout vlcVout);
}
/**
@@ -122,10 +134,16 @@ public interface IVLCVout {
boolean areViewsAttached();
/**
- * Set a callback to receive {@link Callback#onNewLayout} events.
+ * Add a callback to receive {@link Callback#onNewLayout} events.
+ */
+ @MainThread
+ void addCallback(Callback callback);
+
+ /**
+ * Remove a callback.
*/
@MainThread
- void setCallback(Callback callback);
+ void removeCallback(Callback callback);
/**
* Send a mouse event to the native vout.
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 0f601bb..13efa62 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -658,7 +658,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
vlcVout.setSubtitlesView(mPresentation.mSubtitlesSurfaceView);
}
- vlcVout.setCallback(this);
+ vlcVout.addCallback(this);
vlcVout.attachViews();
mPlaybackStarted = true;
@@ -708,6 +708,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mPlaybackStarted = false;
+ mService.removeCallback(this);
+ final IVLCVout vlcVout = mService.getVLCVout();
+ vlcVout.removeCallback(this);
+ vlcVout.detachViews();
if(mSwitchingView && mService != null) {
Log.d(TAG, "mLocation = \"" + mUri + "\"");
mService.showWithoutParse(savedIndexPosition);
@@ -731,13 +735,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
time = 0;
else
time -= 5000; // go back 5 seconds, to compensate loading time
- mService.removeCallback(this);
mService.stop();
- mService.setVideoEnabled(false, false);
-
- final IVLCVout vlcVout = mService.getVLCVout();
- vlcVout.detachViews();
- vlcVout.setCallback(null);
SharedPreferences.Editor editor = mSettings.edit();
// Save position
@@ -2989,4 +2987,12 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mSarDen = sarDen;
changeSurfaceLayout();
}
+
+ @Override
+ public void onSurfacesCreated(IVLCVout vlcVout) {
+ }
+
+ @Override
+ public void onSurfacesDestroyed(IVLCVout vlcVout) {
+ }
}
More information about the Android
mailing list