Java Code Examples for com.google.android.exoplayer2.C#NETWORK_TYPE_OTHER
The following examples show how to use
com.google.android.exoplayer2.C#NETWORK_TYPE_OTHER .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Returns the {@link C.NetworkType} of the current network connection. * * @param context A context to access the connectivity manager. * @return The {@link C.NetworkType} of the current network connection. */ @C.NetworkType public static int getNetworkType(Context context) { if (context == null) { // Note: This is for backward compatibility only (context used to be @Nullable). return C.NETWORK_TYPE_UNKNOWN; } NetworkInfo networkInfo; ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return C.NETWORK_TYPE_UNKNOWN; } try { networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (SecurityException e) { // Expected if permission was revoked. return C.NETWORK_TYPE_UNKNOWN; } if (networkInfo == null || !networkInfo.isConnected()) { return C.NETWORK_TYPE_OFFLINE; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return C.NETWORK_TYPE_WIFI; case ConnectivityManager.TYPE_WIMAX: return C.NETWORK_TYPE_4G; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: return getMobileNetworkType(networkInfo); case ConnectivityManager.TYPE_ETHERNET: return C.NETWORK_TYPE_ETHERNET; default: // VPN, Bluetooth, Dummy. return C.NETWORK_TYPE_OTHER; } }
Example 2
Source File: DefaultBandwidthMeter.java From MediaSDK with Apache License 2.0 | 5 votes |
private synchronized void onConnectivityAction() { int networkType = networkTypeOverrideSet ? networkTypeOverride : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context)); if (this.networkType == networkType) { return; } this.networkType = networkType; if (networkType == C.NETWORK_TYPE_OFFLINE || networkType == C.NETWORK_TYPE_UNKNOWN || networkType == C.NETWORK_TYPE_OTHER) { // It's better not to reset the bandwidth meter for these network types. return; } // Reset the bitrate estimate and report it, along with any bytes transferred. this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); long nowMs = clock.elapsedRealtime(); int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0; maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate); // Reset the remainder of the state. sampleStartTimeMs = nowMs; sampleBytesTransferred = 0; totalBytesTransferred = 0; totalElapsedTimeMs = 0; slidingPercentile.reset(); }
Example 3
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Returns the {@link C.NetworkType} of the current network connection. {@link * C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not * granted or the network connection type couldn't be determined. * * @param context A context to access the connectivity manager. * @return The {@link C.NetworkType} of the current network connection, or {@link * C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or * {@code context} is null. */ public static @C.NetworkType int getNetworkType(@Nullable Context context) { if (context == null) { return C.NETWORK_TYPE_UNKNOWN; } NetworkInfo networkInfo; try { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return C.NETWORK_TYPE_UNKNOWN; } networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (SecurityException e) { // Permission ACCESS_NETWORK_STATE not granted. return C.NETWORK_TYPE_UNKNOWN; } if (networkInfo == null || !networkInfo.isConnected()) { return C.NETWORK_TYPE_OFFLINE; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return C.NETWORK_TYPE_WIFI; case ConnectivityManager.TYPE_WIMAX: return C.NETWORK_TYPE_4G; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: return getMobileNetworkType(networkInfo); case ConnectivityManager.TYPE_ETHERNET: return C.NETWORK_TYPE_ETHERNET; default: // Ethernet, VPN, Bluetooth, Dummy. return C.NETWORK_TYPE_OTHER; } }
Example 4
Source File: Util.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Returns the {@link C.NetworkType} of the current network connection. {@link * C#NETWORK_TYPE_UNKNOWN} will be returned if the {@code ACCESS_NETWORK_STATE} permission is not * granted or the network connection type couldn't be determined. * * @param context A context to access the connectivity manager. * @return The {@link C.NetworkType} of the current network connection, or {@link * C#NETWORK_TYPE_UNKNOWN} if the {@code ACCESS_NETWORK_STATE} permission is not granted or * {@code context} is null. */ public static @C.NetworkType int getNetworkType(@Nullable Context context) { if (context == null) { return C.NETWORK_TYPE_UNKNOWN; } NetworkInfo networkInfo; try { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return C.NETWORK_TYPE_UNKNOWN; } networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (SecurityException e) { // Permission ACCESS_NETWORK_STATE not granted. return C.NETWORK_TYPE_UNKNOWN; } if (networkInfo == null || !networkInfo.isConnected()) { return C.NETWORK_TYPE_OFFLINE; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return C.NETWORK_TYPE_WIFI; case ConnectivityManager.TYPE_WIMAX: return C.NETWORK_TYPE_4G; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: return getMobileNetworkType(networkInfo); case ConnectivityManager.TYPE_ETHERNET: return C.NETWORK_TYPE_ETHERNET; default: // Ethernet, VPN, Bluetooth, Dummy. return C.NETWORK_TYPE_OTHER; } }
Example 5
Source File: Util.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Returns the {@link C.NetworkType} of the current network connection. * * @param context A context to access the connectivity manager. * @return The {@link C.NetworkType} of the current network connection. */ @C.NetworkType public static int getNetworkType(Context context) { if (context == null) { // Note: This is for backward compatibility only (context used to be @Nullable). return C.NETWORK_TYPE_UNKNOWN; } NetworkInfo networkInfo; ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return C.NETWORK_TYPE_UNKNOWN; } try { networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (SecurityException e) { // Expected if permission was revoked. return C.NETWORK_TYPE_UNKNOWN; } if (networkInfo == null || !networkInfo.isConnected()) { return C.NETWORK_TYPE_OFFLINE; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return C.NETWORK_TYPE_WIFI; case ConnectivityManager.TYPE_WIMAX: return C.NETWORK_TYPE_4G; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: return getMobileNetworkType(networkInfo); case ConnectivityManager.TYPE_ETHERNET: return C.NETWORK_TYPE_ETHERNET; default: // VPN, Bluetooth, Dummy. return C.NETWORK_TYPE_OTHER; } }
Example 6
Source File: DefaultBandwidthMeter.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private synchronized void onConnectivityAction() { int networkType = networkTypeOverrideSet ? networkTypeOverride : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context)); if (this.networkType == networkType) { return; } this.networkType = networkType; if (networkType == C.NETWORK_TYPE_OFFLINE || networkType == C.NETWORK_TYPE_UNKNOWN || networkType == C.NETWORK_TYPE_OTHER) { // It's better not to reset the bandwidth meter for these network types. return; } // Reset the bitrate estimate and report it, along with any bytes transferred. this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); long nowMs = clock.elapsedRealtime(); int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0; maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate); // Reset the remainder of the state. sampleStartTimeMs = nowMs; sampleBytesTransferred = 0; totalBytesTransferred = 0; totalElapsedTimeMs = 0; slidingPercentile.reset(); }
Example 7
Source File: Util.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Returns the {@link C.NetworkType} of the current network connection. * * @param context A context to access the connectivity manager. * @return The {@link C.NetworkType} of the current network connection. */ @C.NetworkType public static int getNetworkType(Context context) { if (context == null) { // Note: This is for backward compatibility only (context used to be @Nullable). return C.NETWORK_TYPE_UNKNOWN; } NetworkInfo networkInfo; ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivityManager == null) { return C.NETWORK_TYPE_UNKNOWN; } try { networkInfo = connectivityManager.getActiveNetworkInfo(); } catch (SecurityException e) { // Expected if permission was revoked. return C.NETWORK_TYPE_UNKNOWN; } if (networkInfo == null || !networkInfo.isConnected()) { return C.NETWORK_TYPE_OFFLINE; } switch (networkInfo.getType()) { case ConnectivityManager.TYPE_WIFI: return C.NETWORK_TYPE_WIFI; case ConnectivityManager.TYPE_WIMAX: return C.NETWORK_TYPE_4G; case ConnectivityManager.TYPE_MOBILE: case ConnectivityManager.TYPE_MOBILE_DUN: case ConnectivityManager.TYPE_MOBILE_HIPRI: return getMobileNetworkType(networkInfo); case ConnectivityManager.TYPE_ETHERNET: return C.NETWORK_TYPE_ETHERNET; default: // VPN, Bluetooth, Dummy. return C.NETWORK_TYPE_OTHER; } }
Example 8
Source File: DefaultBandwidthMeter.java From Telegram with GNU General Public License v2.0 | 5 votes |
private synchronized void onConnectivityAction() { int networkType = networkTypeOverrideSet ? networkTypeOverride : (context == null ? C.NETWORK_TYPE_UNKNOWN : Util.getNetworkType(context)); if (this.networkType == networkType) { return; } this.networkType = networkType; if (networkType == C.NETWORK_TYPE_OFFLINE || networkType == C.NETWORK_TYPE_UNKNOWN || networkType == C.NETWORK_TYPE_OTHER) { // It's better not to reset the bandwidth meter for these network types. return; } // Reset the bitrate estimate and report it, along with any bytes transferred. this.bitrateEstimate = getInitialBitrateEstimateForNetworkType(networkType); long nowMs = clock.elapsedRealtime(); int sampleElapsedTimeMs = streamCount > 0 ? (int) (nowMs - sampleStartTimeMs) : 0; maybeNotifyBandwidthSample(sampleElapsedTimeMs, sampleBytesTransferred, bitrateEstimate); // Reset the remainder of the state. sampleStartTimeMs = nowMs; sampleBytesTransferred = 0; totalBytesTransferred = 0; totalElapsedTimeMs = 0; slidingPercentile.reset(); }