[Android] Video player: show an animation when the video is loading

Adrien Maglo git at videolan.org
Mon Mar 17 15:25:19 CET 2014


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Mon Mar 17 15:25:10 2014 +0100| [2e3ea4d8cb37b705363fd2065e32a9a287ef9d89] | committer: Adrien Maglo

Video player: show an animation when the video is loading

Feel free to change the animation and the image.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2e3ea4d8cb37b705363fd2065e32a9a287ef9d89
---

 vlc-android/res/layout/player.xml                  |    7 ++++
 .../vlc/gui/video/VideoPlayerActivity.java         |   35 ++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/vlc-android/res/layout/player.xml b/vlc-android/res/layout/player.xml
index a4e2381..cad86d7 100644
--- a/vlc-android/res/layout/player.xml
+++ b/vlc-android/res/layout/player.xml
@@ -45,6 +45,13 @@
             android:background="@drawable/ic_pause_circle"
             android:visibility="invisible" />
 
+        <ImageView
+            android:id="@+id/player_overlay_loading"
+            android:layout_width="80dp"
+            android:layout_height="80dp"
+            android:layout_centerInParent="true"
+            android:src="@drawable/icon" />
+
         <TextView
             android:id="@+id/player_overlay_info"
             android:layout_width="wrap_content"
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 a150fe3..490f996 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -96,9 +96,14 @@ import android.view.View.OnClickListener;
 import android.view.View.OnSystemUiVisibilityChangeListener;
 import android.view.ViewGroup.LayoutParams;
 import android.view.WindowManager;
+import android.view.animation.Animation;
+import android.view.animation.AnimationSet;
 import android.view.animation.AnimationUtils;
+import android.view.animation.DecelerateInterpolator;
+import android.view.animation.RotateAnimation;
 import android.widget.FrameLayout;
 import android.widget.ImageButton;
+import android.widget.ImageView;
 import android.widget.SeekBar;
 import android.widget.SeekBar.OnSeekBarChangeListener;
 import android.widget.TextView;
@@ -152,6 +157,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
     private TextView mTime;
     private TextView mLength;
     private TextView mInfo;
+    private ImageView mLoading;
     private ImageButton mPlayPause;
     private ImageButton mBackward;
     private ImageButton mForward;
@@ -306,6 +312,9 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
         mSeekbar = (SeekBar) findViewById(R.id.player_overlay_seekbar);
         mSeekbar.setOnSeekBarChangeListener(mSeekListener);
 
+        mLoading = (ImageView) findViewById(R.id.player_overlay_loading);
+        startLoadingAnimation();
+
         mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
         mAudioMax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
 
@@ -776,6 +785,7 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                     break;
                 case EventHandler.MediaPlayerPlaying:
                     Log.i(TAG, "MediaPlayerPlaying");
+                    activity.stopLoadingAnimation();
                     activity.showOverlay();
                     /** FIXME: update the track list when it changes during the
                      *  playback. (#7540) */
@@ -1778,6 +1788,10 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                 mLibVLC.playIndex(savedIndexPosition);
                 dontParse = false;
             }
+            else {
+                stopLoadingAnimation();
+                showOverlay();
+            }
         } else if (savedIndexPosition > -1) {
             AudioServiceController.getInstance().stop(); // Stop the previous playback.
             mLibVLC.setMediaList();
@@ -2038,4 +2052,25 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
                 mSubtitlesSurface.setVisibility(View.VISIBLE);
         }
     }
+
+    /**
+     * Start the video loading animation.
+     */
+    private void startLoadingAnimation() {
+        AnimationSet anim = new AnimationSet(true);
+        RotateAnimation rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
+        rotate.setDuration(800);
+        rotate.setInterpolator(new DecelerateInterpolator());
+        rotate.setRepeatCount(RotateAnimation.INFINITE);
+        anim.addAnimation(rotate);
+        mLoading.startAnimation(anim);
+    }
+
+    /**
+     * Stop the video loading animation.
+     */
+    private void stopLoadingAnimation() {
+        mLoading.setVisibility(View.INVISIBLE);
+        mLoading.clearAnimation();
+    }
 }



More information about the Android mailing list