[Android] Add subs download in video player
Geoffrey Métais
git at videolan.org
Wed May 25 09:56:19 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue May 24 18:46:02 2016 +0200| [851aa192d87586b26ca50a39d18f5c1b986e068b] | committer: Geoffrey Métais
Add subs download in video player
> https://code.videolan.org/videolan/vlc-android/commit/851aa192d87586b26ca50a39d18f5c1b986e068b
---
vlc-android/res/menu/audiosub_tracks.xml | 3 +++
.../src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java | 2 +-
.../org/videolan/vlc/gui/video/VideoPlayerActivity.java | 14 +++++++++++++-
.../src/org/videolan/vlc/util/SubtitlesDownloader.java | 10 ++++++++--
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/vlc-android/res/menu/audiosub_tracks.xml b/vlc-android/res/menu/audiosub_tracks.xml
index 3db8cd1..7838801 100644
--- a/vlc-android/res/menu/audiosub_tracks.xml
+++ b/vlc-android/res/menu/audiosub_tracks.xml
@@ -9,4 +9,7 @@
<item
android:id="@+id/video_menu_subtitles_picker"
android:title="@string/subtitle_select" />
+ <item
+ android:id="@+id/video_menu_subtitles_download"
+ android:title="@string/download_subtitles" />
</menu>
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index 82f8ef0..66b509b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -56,12 +56,12 @@ import org.videolan.vlc.gui.SecondaryActivity;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.gui.preferences.PreferencesUi;
import org.videolan.vlc.gui.video.VideoPlayerActivity;
+import org.videolan.vlc.gui.view.AutoFitRecyclerView;
import org.videolan.vlc.interfaces.IPlaybackSettingsController;
import org.videolan.vlc.media.MediaWrapper;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Strings;
-import org.videolan.vlc.gui.view.AutoFitRecyclerView;
import java.util.ArrayList;
import java.util.Calendar;
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 7d944f6..bcc09db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -112,11 +112,13 @@ import org.videolan.vlc.gui.preferences.PreferencesUi;
import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity;
import org.videolan.vlc.interfaces.IPlaybackSettingsController;
import org.videolan.vlc.media.MediaDatabase;
+import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.media.MediaWrapper;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.FileUtils;
import org.videolan.vlc.util.Permissions;
import org.videolan.vlc.util.Strings;
+import org.videolan.vlc.util.SubtitlesDownloader;
import org.videolan.vlc.util.Util;
import org.videolan.vlc.util.VLCInstance;
@@ -2140,6 +2142,16 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
filePickerIntent.setData(Uri.parse(FileUtils.getParent(mUri.toString())));
context.startActivityForResult(filePickerIntent, 0);
return true;
+ } else if (item.getItemId() == R.id.video_menu_subtitles_download) {
+ if (mUri == null)
+ return false;
+ MediaUtils.getSubs(VideoPlayerActivity.this, mService.getCurrentMediaWrapper(), new SubtitlesDownloader.Callback() {
+ @Override
+ public void onRequestEnded(boolean success) {
+ if (success)
+ getSubtitles();
+ }
+ });
}
return false;
}
@@ -2946,7 +2958,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
mTitle.setText(title);
}
- private void getSubtitles() {
+ public void getSubtitles() {
final String subtitleList_serialized = mSettings.getString(PreferencesActivity.VIDEO_SUBTITLE_FILES, null);
VLCApplication.runBackground(new Runnable() {
@Override
diff --git a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
index 8372d33..b79b052 100644
--- a/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
+++ b/vlc-android/src/org/videolan/vlc/util/SubtitlesDownloader.java
@@ -45,6 +45,7 @@ import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.UiTools;
+import org.videolan.vlc.gui.video.VideoPlayerActivity;
import org.videolan.vlc.media.MediaDatabase;
import org.videolan.vlc.media.MediaWrapper;
@@ -101,7 +102,7 @@ public class SubtitlesDownloader {
mCallback = cb;
Set<String> languages = Collections.singleton(Locale.getDefault().getISO3Language().toLowerCase());
if (AndroidUtil.isHoneycombOrLater()) {
- SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mContext);
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
languages = pref.getStringSet("languages_download_list", languages);
}
final ArrayList<String> finalLanguages = new ArrayList<>(languages);
@@ -497,7 +498,7 @@ public class SubtitlesDownloader {
private void showSnackBar(final String text) {
if (mContext == null)
return;
- if (mContext instanceof AppCompatActivity) {
+ if (mContext instanceof AppCompatActivity && !(mContext instanceof VideoPlayerActivity)) {
mHandler.post(new Runnable() {
@Override
public void run() {
@@ -522,6 +523,11 @@ public class SubtitlesDownloader {
public void handleMessage(Message msg) {
if (mContext == null || mContext.isFinishing())
return;
+ if (mContext instanceof VideoPlayerActivity) {
+ if (msg.what == DIALOG_SHOW)
+ showSnackBar(R.string.downloading_subtitles);
+ return;
+ }
switch (msg.what) {
case DIALOG_SHOW:
mDialog = ProgressDialog.show(mContext, "Subs download", "Connecting...", true);
More information about the Android
mailing list