[Android] [PATCH] show info option only when we have META tracks

Geoffrey Métais geoffrey.metais at gmail.com
Tue Dec 9 18:50:42 CET 2014


---
 .../videolan/vlc/gui/video/MediaInfoFragment.java   |  9 +++++++--
 .../videolan/vlc/gui/video/VideoGridFragment.java   | 21 ++++++++++++++++++---
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
index 98bde10..9027f07 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -28,6 +28,7 @@ import org.videolan.libvlc.Media;
 import org.videolan.libvlc.TrackInfo;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
+import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.util.BitmapUtil;
 import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.VLCInstance;
@@ -124,11 +125,13 @@ public class MediaInfoFragment extends ListFragment {
             int width, height;
             if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
                 width = Math.min(screen.widthPixels, screen.heightPixels);
-                height = width * 9 / 16;
             } else {
                 width = screen.widthPixels /2 ;
             }
-            height = width * videoHeight/videoWidth;
+            if (videoWidth == 0)
+                height = width * 9 / 16;
+            else
+                height = width * videoHeight/videoWidth;
 
             // Get the thumbnail.
             mImage = Bitmap.createBitmap(width, height, Config.ARGB_8888);
@@ -164,6 +167,8 @@ public class MediaInfoFragment extends ListFragment {
             if (track.Type != TrackInfo.TYPE_META)
                 mAdapter.add(track);
         }
+        if (mAdapter.isEmpty())
+            ((MainActivity)getActivity()).popSecondaryFragment();
     }
 
     private Handler mHandler = new MediaInfoHandler(this);
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 76bb1aa..e03d71c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -26,8 +26,11 @@ import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.CyclicBarrier;
 
 import org.videolan.android.ui.SherlockGridFragment;
+import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.LibVlcException;
 import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.libvlc.Media;
+import org.videolan.libvlc.TrackInfo;
 import org.videolan.vlc.MediaDatabase;
 import org.videolan.vlc.MediaGroup;
 import org.videolan.vlc.MediaLibrary;
@@ -97,6 +100,7 @@ public class VideoGridFragment extends SherlockGridFragment implements IBrowser,
 
     private VideoListAdapter mVideoAdapter;
     private MediaLibrary mMediaLibrary;
+    private LibVLC mLibVlc;
     private Thumbnailer mThumbnailer;
     private VideoGridAnimator mAnimator;
     private SwipeRefreshLayout mSwipeRefreshLayout;
@@ -124,6 +128,9 @@ public class VideoGridFragment extends SherlockGridFragment implements IBrowser,
         FragmentActivity activity = getActivity();
         if (activity != null)
             mThumbnailer = new Thumbnailer(activity, activity.getWindowManager().getDefaultDisplay());
+        try {
+            mLibVlc = LibVLC.getInstance();
+        } catch (LibVlcException e) {}
     }
 
     @Override
@@ -340,10 +347,18 @@ public class VideoGridFragment extends SherlockGridFragment implements IBrowser,
 
     private void setContextMenuItems(Menu menu, Media media) {
         long lastTime = media.getTime();
-        if (lastTime > 0) {
-            MenuItem playFromStart = menu.findItem(R.id.video_list_play_from_start);
-            playFromStart.setVisible(true);
+        if (lastTime > 0)
+            menu.findItem(R.id.video_list_play_from_start).setVisible(true);
+
+        boolean hasInfo = false;
+        TrackInfo[] tracks = mLibVlc.readTracksInfo(media.getLocation());
+        for (TrackInfo track : tracks) {
+            if (track.Type != TrackInfo.TYPE_META) {
+                hasInfo = true;
+                break;
+            }
         }
+        menu.findItem(R.id.video_list_info).setVisible(hasInfo);
     }
 
     @Override
-- 
1.9.1



More information about the Android mailing list