media
media copied to clipboard
Fix initial network type
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:
15:33:36.221 12556-12556 DefaultBandwidthMeter D InitialBitrateEstimate: 1000000
15:33:36.348 12556-12556 NetworkTypeObserver D Network type changed from 0 to 2
Note that there was a 127ms interval between the time when the NetworkTypeObserver
was queried by DefaultBandwidthMeter
and the time when the NetworkTypeObserver
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.
I encountered this issue in a different way. Related PR: https://github.com/google/ExoPlayer/pull/10729
@microkatz Any updates on this? TIA.