Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to limit video quality if using mobile data. #1339

Merged
merged 2 commits into from
May 27, 2018

Conversation

Zenopheus
Copy link
Contributor

@Zenopheus Zenopheus commented Apr 21, 2018

Fixes #1259
This limits the user's default video resolution when not connected to WiFi. The user can choose "No Limit"(default) or a specified resolution ("144p" for example). When active the audio stream with the lowest bitrate is also chosen. This differs from the proposed design due to complexity concerns. For example, supporting a "No Video" option would have required a lot of changes to be implemented cleanly.

  • Changes to Settings video & audio settings

    • Added mobile data resolution limit drop down
  • Changes to ListHelper:

    • Automatically limits the default resolution based on user's resolution limit settings. Direct changes to video resolution (from within the player) will not be limited.
    • Automatically limits the default audio bitrate to the lowest available stream if limiting is enabled.
    • Removed some dead code and did some cleanup
    • Make methods private/protected to help understand what was in active use
    • The code now chooses one format over an other using a simple ranking system defined in array constants. I realized I needed to do this in order to choose the most efficient video stream. I did my best to evaluate the video and audio formats based on quality and efficiency. It's not an exact science.
    • Made changes to the tests to support my changes
  • I carefully read the contribution guidelines and agree to them.

* Added a dropdown to video & audio settings
* Changes to ListHelper:
** Limits resolution when code requests the default video resolution
** Limits audio bitrate when code requests the default audio bitrate
** Removed some dead code and did some cleanup
** Make methods private/protected to help understand what was in use
** The code now chooses one format over an other using a simple raking system defined in array constants. I realized I needed to do this in order to choose the most efficient video stream. I did my best to evaluate the video and audio formats based on quality and efficiency. It's not an exact science.
** Made changes to the tests to support my changes
<!-- Limit mobile data usage -->
<string name="limit_mobile_data_usage_key" translatable="false">limit_mobile_data_usage</string>
<string name="limit_mobile_data_usage_value" translatable="false">@string/limit_data_usage_none_key</string>
<string-array name="limit_data_usage_description_list">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description should be put into strings.xml not into the settings_kes.xml file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought strings.xml was for stuff that required translation? None of these contain user facing labels. I was mimicking default_resolution_key, default_resolution_value, and resolution_list_values as listed above. Do you want me to move limit_data_usage_description_list into strings.xml? Should I include resolution_list_values also then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can mark them as nontranslatable than they will not get translated.
I want the settings_keys.xml just contain keys.

<item>240p</item>
<item>144p</item>
</string-array>
<string-array name="limit_data_usage_values_list">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have this list for the other resolution select already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost, resolution_list_values is mostly identical except for the first item: "Best resolution" vs "No limit". I was also bothered by the duplication but I didn't know of a way to share some of the items without more refactoring and I was trying to avoid too many code changes for my first push. We may also want to consider a "No video" item at some point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm ok.

// If the user has chosen to limit resolution to conserve mobile data
// usage then we should also limit our audio usage.
int result;
if (isLimitingDataUsage(context)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not

if (isLimitingDataUsage(context)) {
   return getMostCompactAudioIndex(defaultFormat, audioStreams);
} else {
   return getHighestQualityAudioIndex(defaultFormat, audioStreams);
}
   

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think because my original changes were more complicated (multiple limiting levels). Some people prefer one return at the end of a method so I kept it. It doesn't matter to me either way, I'll throw in the returns.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am an R-Value/functional fan, so I think return would fit well here :)

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

// Load the prefered resolution otherwise the best available
String resolution = preferences != null ? preferences.getString(context.getString(key),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format this line like this:

String resolution = preferences != null
                             ? preferences.getString(context.getString(key), context.getString(value))
                             : context.getString(R.string.best_resolution_key);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

@theScrabi theScrabi changed the title Added the ability to limit video quality if using mobile data. [WIP] Added the ability to limit video quality if using mobile data. Apr 21, 2018
- Moved non-key strings from string_keys.xml to strings.xml
- Code style changes
- Replaced a hard coded key string with resource constant
@theScrabi
Copy link
Member

If ur done please remove the wip sign

@Zenopheus Zenopheus changed the title [WIP] Added the ability to limit video quality if using mobile data. Added the ability to limit video quality if using mobile data. Apr 22, 2018
@theScrabi theScrabi merged commit 646fa87 into TeamNewPipe:dev May 27, 2018
@theScrabi
Copy link
Member

all right nice contribution thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants