[Android] VideoPlayerActivity: don't display loading animations too soon
Thomas Guillem
git at videolan.org
Fri May 27 10:01:50 CEST 2016
vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Fri May 27 10:00:10 2016 +0200| [5cb6e7d9ce73f5e0b7f1b719d9df626ad88721a5] | committer: Thomas Guillem
VideoPlayerActivity: don't display loading animations too soon
This avoid a glitch when opening is too fast.
> https://code.videolan.org/videolan/vlc-android/commit/5cb6e7d9ce73f5e0b7f1b719d9df626ad88721a5
---
vlc-android/res/layout/player.xml | 1 +
vlc-android/res/layout/player_remote_control.xml | 1 +
.../vlc/gui/video/VideoPlayerActivity.java | 48 ++++++++++------------
3 files changed, 24 insertions(+), 26 deletions(-)
diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index 5edbf35..153c741 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -54,6 +54,7 @@
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
+ android:visibility="invisible"
android:src="@drawable/ic_cone_o" />
<LinearLayout
diff --git a/vlc-android/res/layout/player_remote_control.xml b/vlc-android/res/layout/player_remote_control.xml
index 7197d3a..300e731 100644
--- a/vlc-android/res/layout/player_remote_control.xml
+++ b/vlc-android/res/layout/player_remote_control.xml
@@ -69,6 +69,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/ic_cone_o"
+ android:visibility="invisible"
android:top="40dp" />
</RelativeLayout>
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 2f2600b..3bc8ab4 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -208,8 +208,11 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private static final int AUDIO_SERVICE_CONNECTION_FAILED = 5;
private static final int RESET_BACK_LOCK = 6;
private static final int CHECK_VIDEO_TRACKS = 7;
+ private static final int LOADING_ANIMATION = 8;
private static final int HW_ERROR = 1000; // TODO REMOVE
+ private static final int LOADING_ANIMATION_DELAY = 1000;
+
private boolean mDragging;
private boolean mShowing;
private DelayState mPlaybackSetting = DelayState.OFF;
@@ -224,7 +227,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
private View mVerticalBar;
private View mVerticalBarProgress;
private boolean mIsLoading;
- private long mStartBufferingTime = 0;
+ private boolean mIsPlaying = false;
private ImageView mLoading;
private ImageView mTipsBackground;
private ImageView mPlayPause;
@@ -453,7 +456,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (mPresentation != null)
mTipsBackground = (ImageView) findViewById(R.id.player_remote_tips_background);
dimStatusBar(true);
- startLoading();
+ mHandler.sendEmptyMessageDelayed(LOADING_ANIMATION, LOADING_ANIMATION_DELAY);
mSwitchingView = false;
mHardwareAccelerationError = false;
@@ -1539,7 +1542,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
encounteredError();
break;
case MediaPlayer.Event.TimeChanged:
- mStartBufferingTime = 0;
break;
case MediaPlayer.Event.Vout:
updateNavStatus();
@@ -1561,13 +1563,13 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
updatePausable(event.getPausable());
break;
case MediaPlayer.Event.Buffering:
- if (event.getBuffering() == 100f){
- mStartBufferingTime = 0;
- if (mIsLoading)
- stopLoading();
- }
- else
- startLoadingDelayed();
+ if (!mIsPlaying)
+ break;
+ if (event.getBuffering() == 100f)
+ stopLoading();
+ else if (!mHandler.hasMessages(LOADING_ANIMATION) && !mIsLoading
+ && mTouchAction != TOUCH_SEEK && !mDragging)
+ mHandler.sendEmptyMessageDelayed(LOADING_ANIMATION, LOADING_ANIMATION_DELAY);
break;
}
}
@@ -1610,6 +1612,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
switchToAudioMode(true);
}
break;
+ case LOADING_ANIMATION:
+ startLoading();
+ break;
case HW_ERROR:
handleHardwareAccelerationError();
break;
@@ -1623,6 +1628,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
private void onPlaying() {
+ mIsPlaying = true;
stopLoading();
updateNavStatus();
mHandler.sendEmptyMessageDelayed(FADE_OUT, OVERLAY_TIMEOUT);
@@ -1637,7 +1643,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
return;
}
if(mService.expand() == 0) {
- startLoading();
+ mHandler.removeMessages(LOADING_ANIMATION);
+ mHandler.sendEmptyMessageDelayed(LOADING_ANIMATION, LOADING_ANIMATION_DELAY);
Log.d(TAG, "Found a video playlist, expanding it");
mHandler.post(new Runnable() {
@Override
@@ -2824,6 +2831,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
if (mService == null)
return;
mUri = null;
+ mIsPlaying = false;
String title = getResources().getString(R.string.title);
boolean fromStart = false;
String itemTitle = null;
@@ -3267,6 +3275,9 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
* Stop the video loading animation.
*/
private void stopLoading() {
+ mHandler.removeMessages(LOADING_ANIMATION);
+ if (!mIsLoading)
+ return;
mIsLoading = false;
mLoading.setVisibility(View.INVISIBLE);
mLoading.clearAnimation();
@@ -3275,21 +3286,6 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
}
}
- /**
- * If VLC is buffering since 1 second, start the video loading animation
- */
- private void startLoadingDelayed() {
- if (mIsLoading || mTouchAction == TOUCH_SEEK || mDragging)
- return;
- if (mStartBufferingTime == 0) {
- mStartBufferingTime = System.currentTimeMillis();
- return;
- }
- if (System.currentTimeMillis() - mStartBufferingTime > 1000) {
- startLoading();
- }
- }
-
public void onClickOverlayTips(View v) {
mOverlayTips.setVisibility(View.GONE);
}
More information about the Android
mailing list