[Android] Show subtitles presence in Info Panel
Geoffrey Métais
git at videolan.org
Fri Jan 9 17:38:34 CET 2015
vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jan 9 17:37:57 2015 +0100| [2855b7754e19407510dcb4c978621880ab656de3] | committer: Geoffrey Métais
Show subtitles presence in Info Panel
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=2855b7754e19407510dcb4c978621880ab656de3
---
libvlc/src/org/videolan/libvlc/Media.java | 9 ++++++
vlc-android/res/layout-land/media_info.xml | 9 ++++++
vlc-android/res/layout/media_info.xml | 11 +++++++
.../videolan/vlc/gui/video/MediaInfoFragment.java | 33 ++++++++++++++++++--
4 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/libvlc/src/org/videolan/libvlc/Media.java b/libvlc/src/org/videolan/libvlc/Media.java
index e4cf411..02ae924 100644
--- a/libvlc/src/org/videolan/libvlc/Media.java
+++ b/libvlc/src/org/videolan/libvlc/Media.java
@@ -34,6 +34,7 @@ public class Media implements Parcelable {
public final static HashSet<String> VIDEO_EXTENSIONS;
public final static HashSet<String> AUDIO_EXTENSIONS;
+ public final static HashSet<String> SUBTITLES_EXTENSIONS;
static {
final String[] video_extensions = {
@@ -51,12 +52,20 @@ public class Media implements Parcelable {
".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",
".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };
+ final String[] subtitles_extensions = {
+ "idx", "sub", "srt", "ssa", "ass", "smi", "utf", "utf8", "utf-8",
+ "rt", "aqt", "txt", "usf", "jss", "cdg", "psb", "mpsub","mpl2",
+ "pjs", "dks", "stl", "vtt" };
+
VIDEO_EXTENSIONS = new HashSet<String>();
for (String item : video_extensions)
VIDEO_EXTENSIONS.add(item);
AUDIO_EXTENSIONS = new HashSet<String>();
for (String item : audio_extensions)
AUDIO_EXTENSIONS.add(item);
+ SUBTITLES_EXTENSIONS = new HashSet<String>();
+ for (String item : subtitles_extensions)
+ SUBTITLES_EXTENSIONS.add(item);
}
public final static int TYPE_ALL = -1;
diff --git a/vlc-android/res/layout-land/media_info.xml b/vlc-android/res/layout-land/media_info.xml
index 4ac6ac9..9e100cb 100644
--- a/vlc-android/res/layout-land/media_info.xml
+++ b/vlc-android/res/layout-land/media_info.xml
@@ -77,6 +77,15 @@
android:layout_alignBottom="@+id/info_delete"
android:layout_alignTop="@+id/info_delete"
android:gravity="center_vertical"/>
+ <ImageView
+ android:id="@+id/info_subtitles"
+ android:layout_width="20dp"
+ android:layout_height="20dp"
+ android:layout_marginLeft="10dp"
+ android:layout_below="@+id/info_path"
+ android:layout_toRightOf="@+id/size_value"
+ android:src="@drawable/ic_subtitle_circle_normal_o"
+ android:visibility="invisible"/>
<TextView
android:id="@+id/info_delete"
android:layout_width="wrap_content"
diff --git a/vlc-android/res/layout/media_info.xml b/vlc-android/res/layout/media_info.xml
index a6e9096..0503e35 100644
--- a/vlc-android/res/layout/media_info.xml
+++ b/vlc-android/res/layout/media_info.xml
@@ -51,6 +51,8 @@
android:id="@+id/info_path"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:layout_marginLeft="10dp"
+ android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_below="@+id/image_container"/>
<TextView
@@ -67,6 +69,15 @@
android:layout_height="wrap_content"
android:layout_below="@+id/info_path"
android:layout_toRightOf="@+id/size_title"/>
+ <ImageView
+ android:id="@+id/info_subtitles"
+ android:layout_width="20dp"
+ android:layout_height="20dp"
+ android:layout_marginLeft="10dp"
+ android:layout_below="@+id/info_path"
+ android:layout_toRightOf="@+id/size_value"
+ android:src="@drawable/ic_subtitle_circle_normal_o"
+ android:visibility="invisible"/>
<TextView
android:id="@+id/info_delete"
android:layout_width="wrap_content"
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 a7d0afc..d0b141f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/MediaInfoFragment.java
@@ -67,6 +67,7 @@ public class MediaInfoFragment extends ListFragment {
private TextView mPathView;
private ImageButton mPlayButton;
private TextView mDelete;
+ private ImageView mSubtitles;
private TrackInfo[] mTracks;
private MediaInfoAdapter mAdapter;
private final static int NEW_IMAGE = 0;
@@ -74,6 +75,7 @@ public class MediaInfoFragment extends ListFragment {
private final static int NEW_SIZE = 2;
private final static int HIDE_DELETE = 3;
private final static int EXIT = 4;
+ private final static int SHOW_SUBTITLES = 5;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -85,6 +87,7 @@ public class MediaInfoFragment extends ListFragment {
mPathView = (TextView) v.findViewById(R.id.info_path);
mPlayButton = (ImageButton) v.findViewById(R.id.play);
mDelete = (TextView) v.findViewById(R.id.info_delete);
+ mSubtitles = (ImageView) v.findViewById(R.id.info_subtitles);
if (!LibVlcUtil.isICSOrLater())
mDelete.setText(getString(R.string.delete).toUpperCase());
@@ -148,9 +151,26 @@ public class MediaInfoFragment extends ListFragment {
mHandler.obtainMessage(HIDE_DELETE).sendToTarget();
long length = itemFile.length();
mHandler.obtainMessage(NEW_SIZE, Long.valueOf(length)).sendToTarget();
+ checkSubtitles(itemFile);
}
};
+ private void checkSubtitles(File itemFile) {
+ String extension, filename, videoName = Uri.decode(itemFile.getName());
+ videoName = videoName.substring(0, videoName.lastIndexOf('.'));
+ String[] files = itemFile.getParentFile().list();
+ for (int i = 0; i<files.length ; ++i){
+ filename = Uri.decode(files[i]);
+ extension = filename.substring(filename.lastIndexOf('.')+1);
+ if (!Media.SUBTITLES_EXTENSIONS.contains(extension))
+ continue;
+ if (filename.startsWith(videoName)) {
+ mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
+ return;
+ }
+ }
+ }
+
Runnable mLoadImage = new Runnable() {
@Override
public void run() {
@@ -159,12 +179,12 @@ public class MediaInfoFragment extends ListFragment {
} catch (LibVlcException e) {
return;
}
+ mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
int videoHeight = mItem.getHeight();
int videoWidth = mItem.getWidth();
if (videoWidth == 0 || videoHeight == 0)
return;
- mTracks = mLibVlc.readTracksInfo(mItem.getLocation());
mHandler.sendEmptyMessage(NEW_TEXT);
DisplayMetrics screen = new DisplayMetrics();
@@ -207,14 +227,20 @@ public class MediaInfoFragment extends ListFragment {
}
private void updateText() {
+ boolean hasSubs = false;
for (TrackInfo track : mTracks) {
- if (track.Type != TrackInfo.TYPE_META)
+ if (track.Type != TrackInfo.TYPE_META) {
mAdapter.add(track);
+ if (track.Type == TrackInfo.TYPE_TEXT)
+ hasSubs = true;
+ }
}
if (mAdapter.isEmpty()) {
((MainActivity) getActivity()).popSecondaryFragment();
return;
}
+ if (hasSubs)
+ mHandler.obtainMessage(SHOW_SUBTITLES).sendToTarget();
}
private void updateSize(Long size){
@@ -250,6 +276,9 @@ public class MediaInfoFragment extends ListFragment {
((MainActivity) fragment.getActivity()).popSecondaryFragment();
MediaLibrary.getInstance().loadMediaItems(fragment.getActivity(), true);
break;
+ case SHOW_SUBTITLES:
+ fragment.mSubtitles.setVisibility(View.VISIBLE);
+ break;
}
};
More information about the Android
mailing list