mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Check network connection type before choosing the default bitrate
This commit is contained in:
parent
bb9b2d95b5
commit
695f406bd6
1 changed files with 21 additions and 2 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package com.cappielloantonio.play.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
|
||||
|
|
@ -30,8 +32,8 @@ public class MusicUtil {
|
|||
"&v=" + params.get("v") +
|
||||
"&c=" + params.get("c") +
|
||||
"&id=" + song.getId() +
|
||||
"&maxBitRate=" + PreferenceUtil.getInstance(context).getMaxBitrateWifi() +
|
||||
"&format=" + PreferenceUtil.getInstance(context).getAudioTranscodeFormat();
|
||||
"&maxBitRate=" + getBitratePreference(context) +
|
||||
"&format=" + getFormatPreference(context);
|
||||
}
|
||||
|
||||
public static MediaItem getSongDownloadItem(Song song) {
|
||||
|
|
@ -128,4 +130,21 @@ public class MusicUtil {
|
|||
return R.drawable.default_album_art;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getBitratePreference(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
switch (connectivityManager.getActiveNetworkInfo().getType()) {
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateWifi();
|
||||
case ConnectivityManager.TYPE_MOBILE:
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateMobile();
|
||||
default:
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateWifi();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getFormatPreference(Context context) {
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormat();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue