From 5dfa88b50664eca582a7bff44c3df8cbef769963 Mon Sep 17 00:00:00 2001 From: subhadipThinkpad Date: Mon, 7 Jan 2019 02:43:25 +0530 Subject: [PATCH] Video quality selection setting feature added --- .../peertube/activity/SettingsActivity.java | 8 +++++ .../fragment/VideoPlayerFragment.java | 31 ++++++++++++++++--- app/src/main/res/values/array.xml | 12 +++++++ app/src/main/res/xml/pref_general.xml | 8 +++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java index 3d7352d..fa10209 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java @@ -93,6 +93,13 @@ public class SettingsActivity extends AppCompatPreferenceActivity { preference.setSummary(stringValue); return true; } + //check if video quality has changed & provide selected quality + else if (preference.getKey().equals("pref_quality")) { + Toast.makeText(preference.getContext(), "Quality changed", Toast.LENGTH_LONG).show(); + + preference.setSummary(stringValue); + return true; + } preference.setSummary(stringValue); @@ -201,6 +208,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // guidelines. bindPreferenceSummaryToValue(findPreference("pref_api_base")); bindPreferenceSummaryToValue(findPreference("pref_theme")); + bindPreferenceSummaryToValue(findPreference("pref_quality")); } @Override diff --git a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java index 2680e25..bc2474a 100644 --- a/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java +++ b/app/src/main/java/net/schueller/peertube/fragment/VideoPlayerFragment.java @@ -202,11 +202,34 @@ public class VideoPlayerFragment extends Fragment implements VideoRendererEventL assert videoMetaDataFragment != null; videoMetaDataFragment.updateVideoMeta(video, mService); - Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); - - mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); + + String videoQuality = sharedPref.getString("pref_quality", ""); + + //get video quality + if (video.getFiles().size() > 1 && videoQuality.equals("High")) { + + mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); + Log.v(TAG, "urlHigh : " + video.getFiles().get(0).getFileUrl()); + + } else if (video.getFiles().size() >= 2 && videoQuality.equals("Medium")) { + + mService.setCurrentStreamUrl(video.getFiles().get(1).getFileUrl()); + Log.v(TAG, "urlMed : " + video.getFiles().get(1).getFileUrl()); + + } else if (video.getFiles().size() >= 3 && videoQuality.equals("Low")) { + + mService.setCurrentStreamUrl(video.getFiles().get(2).getFileUrl()); + Log.v(TAG, "urlLow : " + video.getFiles().get(2).getFileUrl()); + + } else { + //default quality + mService.setCurrentStreamUrl(video.getFiles().get(0).getFileUrl()); + Log.v(TAG, "url : " + video.getFiles().get(0).getFileUrl()); + } + +// Log.v(TAG, "url : " + video.getFiles().size()); + if (sharedPref.getBoolean("pref_torrent_player", false)) { String stream = video.getFiles().get(0).getTorrentUrl(); diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index e842230..5936a02 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -435,4 +435,16 @@ + + Low + Medium + High + + + + Low + Medium + High + + diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 98b1da9..cee8c5c 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -30,6 +30,14 @@ android:summary="@string/pref_description_language" android:title="@string/pref_language" /> + +