[Android] Video player: Restore 360° navigation

Geoffrey Métais git at videolan.org
Wed Apr 18 13:07:01 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr 18 13:06:39 2018 +0200| [b6c6c1f61c7d502ce378a3f54109e3a4bf838f1c] | committer: Geoffrey Métais

Video player: Restore 360° navigation

> https://code.videolan.org/videolan/vlc-android/commit/b6c6c1f61c7d502ce378a3f54109e3a4bf838f1c
---

 .../vlc/gui/video/VideoPlayerActivity.java         | 34 +++++------------
 .../videolan/vlc/gui/video/VideoTouchDelegate.kt   | 43 +++++++++++-----------
 2 files changed, 31 insertions(+), 46 deletions(-)

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 a24539816..c7f80c421 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -249,7 +249,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private boolean mLockBackButton = false;
     boolean mWasPaused = false;
     private long mSavedTime = -1;
-    private float mSavedRate = 1.f;
 
     /**
      * For uninterrupted switching between audio and video mode
@@ -311,8 +310,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     private OnLayoutChangeListener mOnLayoutChangeListener;
     private AlertDialog mAlertDialog;
 
-    private final DisplayMetrics mScreen = new DisplayMetrics();
-
     protected boolean mIsBenchmark = false;
 
     @Override
@@ -735,7 +732,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         if (mPlaybackStarted || mService == null)
             return;
 
-        mSavedRate = 1.0f;
         mSavedTime = -1;
         mPlaybackStarted = true;
 
@@ -846,14 +842,10 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             mSavedTime = getTime();
             long length = mService.getLength();
             //remove saved position if in the last 5 seconds
-            if (length - mSavedTime < 5000)
-                mSavedTime = 0;
-            else
-                mSavedTime -= 2000; // go back 2 seconds, to compensate loading time
+            if (length - mSavedTime < 5000) mSavedTime = 0;
+            else mSavedTime -= 2000; // go back 2 seconds, to compensate loading time
         }
 
-        mSavedRate = mService.getRate();
-
         mService.setRate(1.0f, false);
         mService.stop();
     }
@@ -1094,20 +1086,16 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                 if (mIsNavMenu)
                     return navigateDvdMenu(keyCode);
                 else if (!mShowing) {
-                    if (mFov == 0f)
-                        seekDelta(-10000);
-                    else
-                        mService.updateViewpoint(-5f, 0f, 0f, 0f, false);
+                    if (mFov == 0f) seekDelta(-10000);
+                    else mService.updateViewpoint(-5f, 0f, 0f, 0f, false);
                     return true;
                 }
             case KeyEvent.KEYCODE_DPAD_RIGHT:
                 if (mIsNavMenu)
                     return navigateDvdMenu(keyCode);
                 else if (!mShowing) {
-                    if (mFov == 0f)
-                        seekDelta(10000);
-                    else
-                        mService.updateViewpoint(5f, 0f, 0f, 0f, false);
+                    if (mFov == 0f) seekDelta(10000);
+                    else mService.updateViewpoint(5f, 0f, 0f, 0f, false);
                     return true;
                 }
             case KeyEvent.KEYCODE_DPAD_UP:
@@ -1117,10 +1105,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
                     volumeUp();
                     return true;
                 } else if (!mShowing) {
-                    if (mFov == 0f)
-                        showAdvancedOptions();
-                    else
-                        mService.updateViewpoint(0f, -5f, 0f, 0f, false);
+                    if (mFov == 0f) showAdvancedOptions();
+                    else mService.updateViewpoint(0f, -5f, 0f, 0f, false);
                     return true;
                 }
             case KeyEvent.KEYCODE_DPAD_DOWN:
@@ -1985,8 +1971,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
         return mService != null && mTouchDelegate.onTouchEvent(event);
     }
 
-    boolean updateViewpoint(float yaw, float pitch) {
-        return mService.updateViewpoint(yaw, pitch, 0, 0, false);
+    boolean updateViewpoint(float yaw, float pitch, float fov) {
+        return mService.updateViewpoint(yaw, pitch, 0, fov, false);
     }
 
     void initAudioVolume() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
index dedd5a48b..54e940b87 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoTouchDelegate.kt
@@ -95,30 +95,29 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
                 player.sendMouseEvent(MotionEvent.ACTION_DOWN, xTouch, yTouch)
             }
             MotionEvent.ACTION_MOVE -> {
-                if (mTouchAction != TOUCH_IGNORE) {// Mouse events for the core
-                    player.sendMouseEvent(MotionEvent.ACTION_MOVE, xTouch, yTouch)
-
-                    if (player.fov == 0f) {
-                        // No volume/brightness action if coef < 2 or a secondary display is connected
-                        //TODO : Volume action when a secondary display is connected
-                        if (mTouchAction != TOUCH_SEEK && coef > 2 && player.isOnPrimaryDisplay) {
-                            if (Math.abs(yChanged / screenConfig.yRange) < 0.05)
-                                return false
-                            mTouchY = event.rawY
-                            mTouchX = event.rawX
-                            doVerticalTouchAction(yChanged)
-                        } else {
-                            // Seek (Right or Left move)
-                            doSeekTouch(Math.round(deltaY), if (rtl) -xgesturesize else xgesturesize, false)
-                        }
-                    } else {
+                if (mTouchAction == TOUCH_IGNORE) return false
+                // Mouse events for the core
+                player.sendMouseEvent(MotionEvent.ACTION_MOVE, xTouch, yTouch)
+
+                if (player.fov == 0f) {
+                    // No volume/brightness action if coef < 2 or a secondary display is connected
+                    //TODO : Volume action when a secondary display is connected
+                    if (mTouchAction != TOUCH_SEEK && coef > 2 && player.isOnPrimaryDisplay) {
+                        if (Math.abs(yChanged / screenConfig.yRange) < 0.05) return false
                         mTouchY = event.rawY
                         mTouchX = event.rawX
-                        mTouchAction = TOUCH_MOVE
-                        val yaw = player.fov * -xChanged / screenConfig.xRange.toFloat()
-                        val pitch = player.fov * -yChanged / screenConfig.xRange.toFloat()
-                        player.updateViewpoint(yaw, pitch)
+                        doVerticalTouchAction(yChanged)
+                    } else {
+                        // Seek (Right or Left move)
+                        doSeekTouch(Math.round(deltaY), if (rtl) -xgesturesize else xgesturesize, false)
                     }
+                } else {
+                    mTouchY = event.rawY
+                    mTouchX = event.rawX
+                    mTouchAction = TOUCH_MOVE
+                    val yaw = player.fov * -xChanged / screenConfig.xRange.toFloat()
+                    val pitch = player.fov * -yChanged / screenConfig.xRange.toFloat()
+                    player.updateViewpoint(yaw, pitch, 0f)
                 }
             }
             MotionEvent.ACTION_UP -> {
@@ -284,7 +283,7 @@ class VideoTouchDelegate(private val player: VideoPlayerActivity,
         override fun onScale(detector: ScaleGestureDetector): Boolean {
             if (player.fov != 0f) {
                 val diff = VideoPlayerActivity.DEFAULT_FOV * (1 - detector.scaleFactor)
-                if (player.updateViewpoint(0f, 0f)) {
+                if (player.updateViewpoint(0f, 0f, diff)) {
                     player.fov = Math.min(Math.max(MIN_FOV, player.fov + diff), MAX_FOV)
                     return true
                 }



More information about the Android mailing list