mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Check network connection type before choosing the default bitrate and transcoding format
This commit is contained in:
parent
695f406bd6
commit
4a6ea47457
5 changed files with 61 additions and 21 deletions
|
|
@ -2,7 +2,6 @@ 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;
|
||||
|
||||
|
|
@ -22,9 +21,11 @@ public class MusicUtil {
|
|||
private static final String TAG = "MusicUtil";
|
||||
|
||||
public static String getSongStreamUri(Context context, Song song) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
Map<String, String> params = App.getSubsonicClientInstance(App.getInstance(), false).getParams();
|
||||
|
||||
return App.getSubsonicClientInstance(App.getInstance(), false).getUrl() +
|
||||
String uri = App.getSubsonicClientInstance(App.getInstance(), false).getUrl() +
|
||||
"stream" +
|
||||
"?u=" + params.get("u") +
|
||||
"&s=" + params.get("s") +
|
||||
|
|
@ -32,8 +33,12 @@ public class MusicUtil {
|
|||
"&v=" + params.get("v") +
|
||||
"&c=" + params.get("c") +
|
||||
"&id=" + song.getId() +
|
||||
"&maxBitRate=" + getBitratePreference(context) +
|
||||
"&format=" + getFormatPreference(context);
|
||||
"&maxBitRate=" + getBitratePreference(context, connectivityManager.getActiveNetworkInfo().getType()) +
|
||||
"&format=" + getTranscodingFormatPreference(context, connectivityManager.getActiveNetworkInfo().getType());
|
||||
|
||||
Log.d(TAG, "getSongStreamUri(): " + uri);
|
||||
|
||||
return uri;
|
||||
}
|
||||
|
||||
public static MediaItem getSongDownloadItem(Song song) {
|
||||
|
|
@ -131,10 +136,8 @@ public class MusicUtil {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getBitratePreference(Context context) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
switch (connectivityManager.getActiveNetworkInfo().getType()) {
|
||||
private static String getBitratePreference(Context context, int connectionType) {
|
||||
switch (connectionType) {
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
return PreferenceUtil.getInstance(context).getMaxBitrateWifi();
|
||||
case ConnectivityManager.TYPE_MOBILE:
|
||||
|
|
@ -144,7 +147,14 @@ public class MusicUtil {
|
|||
}
|
||||
}
|
||||
|
||||
private static String getFormatPreference(Context context) {
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormat();
|
||||
private static String getTranscodingFormatPreference(Context context, int connectionType) {
|
||||
switch (connectionType) {
|
||||
case ConnectivityManager.TYPE_WIFI:
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatWifi();
|
||||
case ConnectivityManager.TYPE_MOBILE:
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatMobile();
|
||||
default:
|
||||
return PreferenceUtil.getInstance(context).getAudioTranscodeFormatWifi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ public class PreferenceUtil {
|
|||
public static final String MEDIA_CACHE_SIZE = "media_cache_size";
|
||||
public static final String MAX_BITRATE_WIFI = "max_bitrate_wifi";
|
||||
public static final String MAX_BITRATE_MOBILE = "max_bitrate_mobile";
|
||||
public static final String AUDIO_TRANSCODE_FORMAT = "audio_transcode_format";
|
||||
public static final String AUDIO_TRANSCODE_FORMAT_WIFI = "audio_transcode_format_wifi";
|
||||
public static final String AUDIO_TRANSCODE_FORMAT_MOBILE = "audio_transcode_format_mobile";
|
||||
public static final String WIFI_ONLY = "wifi_only";
|
||||
|
||||
private static PreferenceUtil sInstance;
|
||||
|
|
@ -145,8 +146,12 @@ public class PreferenceUtil {
|
|||
return mPreferences.getString(MAX_BITRATE_MOBILE, "0");
|
||||
}
|
||||
|
||||
public final String getAudioTranscodeFormat() {
|
||||
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT, "raw");
|
||||
public final String getAudioTranscodeFormatWifi() {
|
||||
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_WIFI, "raw");
|
||||
}
|
||||
|
||||
public final String getAudioTranscodeFormatMobile() {
|
||||
return mPreferences.getString(AUDIO_TRANSCODE_FORMAT_MOBILE, "raw");
|
||||
}
|
||||
|
||||
public final boolean isWifiOnly() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue