Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
NetworkTypeObserver initialises the default network type as
C.NETWORK_TYPE_UNKNOWN
and then registers for connectivity change callback. This works fine if we receive a connectivity change update quickly.But, sometimes this callback takes time and so DefaultBandwidthMeter assumes network type as unknown and initialises the initial bitrateEstimate as 1Mbps (DEFAULT_INITIAL_BITRATE_ESTIMATE). This initial bitrate estimate is used to select the initial track in playback and so it is vital to get the correct initial bitrate estimate based on the network type. Otherwise even when using a high-speed Wifi connection, initial bitrate estimate will be 1Mbps and forces the player to select a representation with initial bitrate as 1 Mbps (1Mbps X BANDWIDTH_FRACTION).
Eg from Pixel2:
Note that there was a 127ms interval between the time when the
NetworkTypeObserver
was queried byDefaultBandwidthMeter
and the time when theNetworkTypeObserver
was able to update itself based on the connectivity change update.Related discussion explains that it was done this way to differentiate between 4G and 5G NSA. But it affects more playbacks as we get network type as unknown even for wifi or ethernet connections.
Solution:
Use
ConnectivityManager#ActiveNetworkInfo
to pick an optimal initial network type and then let connectivity-change-update callbacks to alter the network type.