[Android] Do not permit seeking on an unseekable stream

Edward Wang git at videolan.org
Sat Feb 23 19:09:26 CET 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Sat Feb 23 12:48:53 2013 -0500| [6264ca30f9f26d32abf5f49139dbf8193ef4f0b2] | committer: Edward Wang

Do not permit seeking on an unseekable stream

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

 vlc-android/res/values-fr/strings.xml              |    1 +
 vlc-android/res/values/strings.xml                 |    1 +
 .../vlc/gui/video/VideoPlayerActivity.java         |    8 ++++++-
 .../videolan/vlc/interfaces/IPlayerControl.java    |    2 ++
 .../videolan/vlc/widget/PlayerControlWheel.java    |   23 ++++++++++++++++----
 5 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/values-fr/strings.xml b/vlc-android/res/values-fr/strings.xml
index 1768da7..61b0c8b 100644
--- a/vlc-android/res/values-fr/strings.xml
+++ b/vlc-android/res/values-fr/strings.xml
@@ -89,6 +89,7 @@
     <string name="surface_fill">Etirer</string>
     <string name="surface_original">Centrer</string>
     <string name="thumbnail">Miniature</string>
+    <string name="unseekable_stream">Flux indéplaçable</string>
     <string name="refresh">Rafraîchir</string>
     <string name="track_audio">Piste audio</string>
     <string name="track_video">Piste vidéo</string>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index a21e8fe..1aab6c6 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -98,6 +98,7 @@
     <string name="surface_fill">Fill</string>
     <string name="surface_original">Center</string>
     <string name="thumbnail">Thumbnail</string>
+    <string name="unseekable_stream">Unseekable stream</string>
     <string name="refresh">Refresh</string>
     <string name="track_audio">Audio track</string>
     <string name="track_video">Video track</string>
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 c64a3e2..0d4599d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * VideoPlayerActivity.java
  *****************************************************************************
- * Copyright © 2011-2012 VLC authors and VideoLAN
+ * Copyright © 2011-2013 VLC authors and VideoLAN
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1028,6 +1028,9 @@ public class VideoPlayerActivity extends Activity {
 
         @Override
         public void onSeek(int delta) {
+            // unseekable stream
+            if(mLibVLC.getLength() <= 0) return;
+
             long position = mLibVLC.getTime() + delta;
             if (position < 0) position = 0;
             mLibVLC.setTime(position);
@@ -1036,6 +1039,8 @@ public class VideoPlayerActivity extends Activity {
 
         @Override
         public void onSeekTo(long position) {
+            // unseekable stream
+            if(mLibVLC.getLength() <= 0) return;
             mLibVLC.setTime(position);
             mTime.setText(Util.millisToString(position));
         }
@@ -1236,6 +1241,7 @@ public class VideoPlayerActivity extends Activity {
         int length = (int) mLibVLC.getLength();
         // Update all view elements
 
+        mControls.setSeekable(length > 0);
         mSeekbar.setMax(length);
         mSeekbar.setProgress(time);
         mSysTime.setText(DateFormat.format("kk:mm", System.currentTimeMillis()));
diff --git a/vlc-android/src/org/videolan/vlc/interfaces/IPlayerControl.java b/vlc-android/src/org/videolan/vlc/interfaces/IPlayerControl.java
index 9801cd3..db0e904 100644
--- a/vlc-android/src/org/videolan/vlc/interfaces/IPlayerControl.java
+++ b/vlc-android/src/org/videolan/vlc/interfaces/IPlayerControl.java
@@ -24,5 +24,7 @@ package org.videolan.vlc.interfaces;
 public interface IPlayerControl {
     void setState(boolean isPlaying);
 
+    void setSeekable(boolean isSeekable);
+
     void setOnPlayerControlListener(OnPlayerControlListener listener);
 }
diff --git a/vlc-android/src/org/videolan/vlc/widget/PlayerControlWheel.java b/vlc-android/src/org/videolan/vlc/widget/PlayerControlWheel.java
index 61319d7..7387837 100644
--- a/vlc-android/src/org/videolan/vlc/widget/PlayerControlWheel.java
+++ b/vlc-android/src/org/videolan/vlc/widget/PlayerControlWheel.java
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * PlayerControlWheel.java
  *****************************************************************************
- * Copyright © 2012 VLC authors and VideoLAN
+ * Copyright © 2012-2013 VLC authors and VideoLAN
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@ package org.videolan.vlc.widget;
 
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.interfaces.IPlayerControl;
 import org.videolan.vlc.interfaces.OnPlayerControlListener;
 
@@ -36,6 +37,7 @@ public class PlayerControlWheel extends LinearLayout implements IPlayerControl {
     private final SeekBar mWheel;
     private OnPlayerControlListener listener = null;
 
+    private boolean mSeekable = true;
     private static final int WHEEL_DEAD_ZONE = 7;
     private static final int WHEEL_RANGE = 60;
     private int mMiddle = 0;
@@ -67,7 +69,7 @@ public class PlayerControlWheel extends LinearLayout implements IPlayerControl {
                 // if in dead zone, pause/unpause
                 if (mSeekTo < 0)
                     listener.onPlayPause();
-                else
+                else if(mSeekable)
                     listener.onSeekTo(mSeekTo);
                 listener.onShowInfo(null);
             }
@@ -85,8 +87,16 @@ public class PlayerControlWheel extends LinearLayout implements IPlayerControl {
             }
             else
                 delta = 0;
-            if (mSeekTo >= 0 && listener != null)
-                listener.onShowInfo(String.format("%s%ds (%s)", delta >= 0 ? "+" : "", delta, Util.millisToString(mSeekTo)));
+            if(mSeekTo >= 0 && listener != null)
+                if(mSeekable)
+                    listener.onShowInfo(String.format("%s%ds (%s)", delta >= 0 ? "+" : "", delta, Util.millisToString(mSeekTo)));
+                else
+                    listener.onShowInfo(VLCApplication.getAppContext().getString(R.string.unseekable_stream));
+
+            if(!mSeekable) {
+                // if the stream is unseekable do not show the user a seeking bar
+                seekBar.setProgress(mMiddle);
+            }
         }
     };
 
@@ -108,4 +118,9 @@ public class PlayerControlWheel extends LinearLayout implements IPlayerControl {
     public void setOnPlayerControlListener(OnPlayerControlListener listener) {
         this.listener = listener;
     }
+
+    @Override
+    public void setSeekable(boolean isSeekable) {
+        mSeekable = isSeekable;
+    }
 }



More information about the Android mailing list