diff --git a/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java b/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java index eccfc0919..5b3c68c2e 100644 --- a/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java +++ b/app/src/main/java/org/schabi/newpipe/detail/ActionBarHandler.java @@ -119,15 +119,32 @@ class ActionBarHandler { .getString(activity.getString(R.string.default_resolution_key), activity.getString(R.string.default_resolution_value)); + String preferedFormat = defaultPreferences + .getString(activity.getString(R.string.preferred_video_format_key), + activity.getString(R.string.preferred_video_format_default)); + + // first try to find the one with the right resolution + int selectedFormat = 0; for (int i = 0; i < videoStreams.size(); i++) { VideoStream item = videoStreams.get(i); if (defaultResolution.equals(item.resolution)) { - return i; + selectedFormat = i; } } + + // than try to find the one with the right resolution and format + for (int i = 0; i < videoStreams.size(); i++) { + VideoStream item = videoStreams.get(i); + if (defaultResolution.equals(item.resolution) + && preferedFormat.equals(MediaFormat.getNameById(item.format))) { + selectedFormat = i; + } + } + + // this is actually an error, // but maybe there is really no stream fitting to the default value. - return 0; + return selectedFormat; } public void setupMenu(Menu menu, MenuInflater inflater) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java index d6af888fb..b30b2af48 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsFragment.java @@ -22,6 +22,7 @@ import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; import java.util.ArrayList; +import java.util.List; import info.guardianproject.netcipher.proxy.OrbotHelper; @@ -52,6 +53,7 @@ public class SettingsFragment extends PreferenceFragment SharedPreferences.OnSharedPreferenceChangeListener prefListener; // get keys String DEFAULT_RESOLUTION_PREFERENCE; + String PREFERRED_VIDEO_FORMAT_PREFERENCE; String DEFAULT_AUDIO_FORMAT_PREFERENCE; String SEARCH_LANGUAGE_PREFERENCE; String DOWNLOAD_PATH_PREFERENCE; @@ -59,6 +61,7 @@ public class SettingsFragment extends PreferenceFragment String USE_TOR_KEY; String THEME; private ListPreference defaultResolutionPreference; + private ListPreference preferredVideoFormatPreference; private ListPreference defaultAudioFormatPreference; private ListPreference searchLanguagePreference; private Preference downloadPathPreference; @@ -77,6 +80,7 @@ public class SettingsFragment extends PreferenceFragment // get keys DEFAULT_RESOLUTION_PREFERENCE = getString(R.string.default_resolution_key); + PREFERRED_VIDEO_FORMAT_PREFERENCE = getString(R.string.preferred_video_format_key); DEFAULT_AUDIO_FORMAT_PREFERENCE = getString(R.string.default_audio_format_key); SEARCH_LANGUAGE_PREFERENCE = getString(R.string.search_language_key); DOWNLOAD_PATH_PREFERENCE = getString(R.string.download_path_key); @@ -87,6 +91,8 @@ public class SettingsFragment extends PreferenceFragment // get pref objects defaultResolutionPreference = (ListPreference) findPreference(DEFAULT_RESOLUTION_PREFERENCE); + preferredVideoFormatPreference = + (ListPreference) findPreference(PREFERRED_VIDEO_FORMAT_PREFERENCE); defaultAudioFormatPreference = (ListPreference) findPreference(DEFAULT_AUDIO_FORMAT_PREFERENCE); searchLanguagePreference = @@ -254,6 +260,9 @@ public class SettingsFragment extends PreferenceFragment defaultResolutionPreference.setSummary( defaultPreferences.getString(DEFAULT_RESOLUTION_PREFERENCE, getString(R.string.default_resolution_value))); + preferredVideoFormatPreference.setSummary( + defaultPreferences.getString(PREFERRED_VIDEO_FORMAT_PREFERENCE, + getString(R.string.preferred_video_format_default))); defaultAudioFormatPreference.setSummary( defaultPreferences.getString(DEFAULT_AUDIO_FORMAT_PREFERENCE, getString(R.string.default_audio_format_value))); diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 99dd0f390..27cd19554 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -22,6 +22,14 @@ 144p + preferrfed_video_format + WebM + + WebM + MPEG-4 + 3GPP + + show_play_with_kodi theme diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 730d06187..cdf20f441 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -45,6 +45,7 @@ Display an option to play a video via Kodi media center. Audio Default audio format + Preferred video format WebM — free format m4a — better quality Theme diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 88dc06e10..ee462ff35 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -25,6 +25,13 @@ android:entryValues="@array/resolution_list" android:defaultValue="@string/default_resolution_value"/> + +