Initial support for buffer length and network timeout in Settings
This commit is contained in:
parent
112b1a3356
commit
6390d9235f
|
@ -85,4 +85,48 @@
|
||||||
<item>@string/settings.max_bitrate_unlimited</item>
|
<item>@string/settings.max_bitrate_unlimited</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="bufferLengthValues">
|
||||||
|
<item>2</item>
|
||||||
|
<item>5</item>
|
||||||
|
<item>8</item>
|
||||||
|
<item>10</item>
|
||||||
|
<item>12</item>
|
||||||
|
<item>15</item>
|
||||||
|
<item>20</item>
|
||||||
|
<item>30</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="bufferLengthNames">
|
||||||
|
<item>@string/settings.buffer_length_2</item>
|
||||||
|
<item>@string/settings.buffer_length_5</item>
|
||||||
|
<item>@string/settings.buffer_length_8</item>
|
||||||
|
<item>@string/settings.buffer_length_10</item>
|
||||||
|
<item>@string/settings.buffer_length_12</item>
|
||||||
|
<item>@string/settings.buffer_length_15</item>
|
||||||
|
<item>@string/settings.buffer_length_20</item>
|
||||||
|
<item>@string/settings.buffer_length_30</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="networkTimeoutValues">
|
||||||
|
<item>15000</item>
|
||||||
|
<item>30000</item>
|
||||||
|
<item>45000</item>
|
||||||
|
<item>60000</item>
|
||||||
|
<item>75000</item>
|
||||||
|
<item>90000</item>
|
||||||
|
<item>105000</item>
|
||||||
|
<item>120000</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="networkTimeoutNames">
|
||||||
|
<item>@string/settings.network_timeout_15000</item>
|
||||||
|
<item>@string/settings.network_timeout_30000</item>
|
||||||
|
<item>@string/settings.network_timeout_45000</item>
|
||||||
|
<item>@string/settings.network_timeout_60000</item>
|
||||||
|
<item>@string/settings.network_timeout_75000</item>
|
||||||
|
<item>@string/settings.network_timeout_90000</item>
|
||||||
|
<item>@string/settings.network_timeout_105000</item>
|
||||||
|
<item>@string/settings.network_timeout_120000</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -185,6 +185,24 @@
|
||||||
<string name="settings.media_button_summary">Respond to phone, headset and Bluetooth media buttons</string>
|
<string name="settings.media_button_summary">Respond to phone, headset and Bluetooth media buttons</string>
|
||||||
<string name="settings.screen_lit_title">Keep screen on</string>
|
<string name="settings.screen_lit_title">Keep screen on</string>
|
||||||
<string name="settings.screen_lit_summary">Keeping the screen on while downloading improves download speed.</string>
|
<string name="settings.screen_lit_summary">Keeping the screen on while downloading improves download speed.</string>
|
||||||
|
<string name="settings.buffer_length">Buffer length</string>
|
||||||
|
<string name="settings.network_timeout">Network timeout</string>
|
||||||
|
<string name="settings.buffer_length_2">2 seconds</string>
|
||||||
|
<string name="settings.buffer_length_5">5 seconds</string>
|
||||||
|
<string name="settings.buffer_length_8">8 seconds</string>
|
||||||
|
<string name="settings.buffer_length_10">10 seconds</string>
|
||||||
|
<string name="settings.buffer_length_12">12 seconds</string>
|
||||||
|
<string name="settings.buffer_length_15">15 seconds</string>
|
||||||
|
<string name="settings.buffer_length_20">20 seconds</string>
|
||||||
|
<string name="settings.buffer_length_30">30 seconds</string>
|
||||||
|
<string name="settings.network_timeout_15000">15 seconds</string>
|
||||||
|
<string name="settings.network_timeout_30000">30 seconds</string>
|
||||||
|
<string name="settings.network_timeout_45000">45 seconds</string>
|
||||||
|
<string name="settings.network_timeout_60000">60 seconds</string>
|
||||||
|
<string name="settings.network_timeout_75000">75 seconds</string>
|
||||||
|
<string name="settings.network_timeout_90000">90 seconds</string>
|
||||||
|
<string name="settings.network_timeout_105000">105 seconds</string>
|
||||||
|
<string name="settings.network_timeout_120000">120 seconds</string>
|
||||||
|
|
||||||
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
|
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,20 @@
|
||||||
a:key="wifiRequiredForDownload"
|
a:key="wifiRequiredForDownload"
|
||||||
a:defaultValue="false"/>
|
a:defaultValue="false"/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
a:title="@string/settings.buffer_length"
|
||||||
|
a:key="bufferLength"
|
||||||
|
a:defaultValue="5"
|
||||||
|
a:entryValues="@array/bufferLengthValues"
|
||||||
|
a:entries="@array/bufferLengthNames"/>
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
a:title="@string/settings.network_timeout"
|
||||||
|
a:key="networkTimeout"
|
||||||
|
a:defaultValue="15000"
|
||||||
|
a:entryValues="@array/networkTimeoutValues"
|
||||||
|
a:entries="@array/networkTimeoutNames"/>
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|
|
@ -55,6 +55,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
private ListPreference cacheSize;
|
private ListPreference cacheSize;
|
||||||
private EditTextPreference cacheLocation;
|
private EditTextPreference cacheLocation;
|
||||||
private ListPreference preloadCount;
|
private ListPreference preloadCount;
|
||||||
|
private ListPreference bufferLength;
|
||||||
|
private ListPreference networkTimeout;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -67,6 +69,8 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
cacheSize = (ListPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
|
cacheSize = (ListPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_SIZE);
|
||||||
cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
|
cacheLocation = (EditTextPreference) findPreference(Constants.PREFERENCES_KEY_CACHE_LOCATION);
|
||||||
preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
|
preloadCount = (ListPreference) findPreference(Constants.PREFERENCES_KEY_PRELOAD_COUNT);
|
||||||
|
bufferLength = (ListPreference) findPreference(Constants.PREFERENCES_KEY_BUFFER_LENGTH);
|
||||||
|
networkTimeout = (ListPreference) findPreference(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT);
|
||||||
|
|
||||||
findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,6 +152,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
|
||||||
cacheSize.setSummary(cacheSize.getEntry());
|
cacheSize.setSummary(cacheSize.getEntry());
|
||||||
cacheLocation.setSummary(cacheLocation.getText());
|
cacheLocation.setSummary(cacheLocation.getText());
|
||||||
preloadCount.setSummary(preloadCount.getEntry());
|
preloadCount.setSummary(preloadCount.getEntry());
|
||||||
|
bufferLength.setSummary(bufferLength.getEntry());
|
||||||
|
networkTimeout.setSummary(networkTimeout.getEntry());
|
||||||
|
|
||||||
for (ServerSettings ss : serverSettings.values()) {
|
for (ServerSettings ss : serverSettings.values()) {
|
||||||
ss.update();
|
ss.update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ import net.sourceforge.subsonic.androidapp.util.Util;
|
||||||
*/
|
*/
|
||||||
public class CachedMusicService implements MusicService {
|
public class CachedMusicService implements MusicService {
|
||||||
|
|
||||||
private static final int MUSIC_DIR_CACHE_SIZE = 20;
|
private static final int MUSIC_DIR_CACHE_SIZE = 50;
|
||||||
private static final int TTL_MUSIC_DIR = 5 * 60; // Five minutes
|
private static final int TTL_MUSIC_DIR = 5 * 60; // Five minutes
|
||||||
|
|
||||||
private final MusicService musicService;
|
private final MusicService musicService;
|
||||||
|
|
|
@ -83,6 +83,10 @@ public class DownloadFile {
|
||||||
return song.getBitRate() == null ? 160 : song.getBitRate();
|
return song.getBitRate() == null ? 160 : song.getBitRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getBufferLength() {
|
||||||
|
return Util.getBufferLength(this.context);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void download() {
|
public synchronized void download() {
|
||||||
FileUtil.createDirectoryForParent(saveFile);
|
FileUtil.createDirectoryForParent(saveFile);
|
||||||
failed = false;
|
failed = false;
|
||||||
|
@ -203,11 +207,11 @@ public class DownloadFile {
|
||||||
Log.i(TAG, "Acquired wake lock " + wakeLock);
|
Log.i(TAG, "Acquired wake lock " + wakeLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveFile.exists()) {
|
if (saveFile.exists() && saveFile.length() == song.getSize()) {
|
||||||
Log.i(TAG, saveFile + " already exists. Skipping.");
|
Log.i(TAG, saveFile + " already exists. Skipping.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (completeFile.exists()) {
|
if (completeFile.exists() && completeFile.length() == song.getSize()) {
|
||||||
if (save) {
|
if (save) {
|
||||||
Util.atomicCopy(completeFile, saveFile);
|
Util.atomicCopy(completeFile, saveFile);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -881,8 +881,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
||||||
|
|
||||||
private class BufferTask extends CancellableTask {
|
private class BufferTask extends CancellableTask {
|
||||||
|
|
||||||
private static final int BUFFER_LENGTH_SECONDS = 5;
|
|
||||||
|
|
||||||
private final DownloadFile downloadFile;
|
private final DownloadFile downloadFile;
|
||||||
private final int position;
|
private final int position;
|
||||||
private final long expectedFileSize;
|
private final long expectedFileSize;
|
||||||
|
@ -893,9 +891,9 @@ public class DownloadServiceImpl extends Service implements DownloadService {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
partialFile = downloadFile.getPartialFile();
|
partialFile = downloadFile.getPartialFile();
|
||||||
|
|
||||||
// Calculate roughly how many bytes BUFFER_LENGTH_SECONDS corresponds to.
|
// Calculate roughly how many bytes buffer length corresponds to.
|
||||||
int bitRate = downloadFile.getBitRate();
|
int bitRate = downloadFile.getBitRate();
|
||||||
long byteCount = Math.max(100000, bitRate * 1024 / 8 * BUFFER_LENGTH_SECONDS);
|
long byteCount = Math.max(100000, bitRate * 1024 / 8 * downloadFile.getBufferLength());
|
||||||
|
|
||||||
// Find out how large the file should grow before resuming playback.
|
// Find out how large the file should grow before resuming playback.
|
||||||
expectedFileSize = partialFile.length() + byteCount;
|
expectedFileSize = partialFile.length() + byteCount;
|
||||||
|
|
|
@ -670,6 +670,8 @@ public class RESTMusicService implements MusicService {
|
||||||
new UsernamePasswordCredentials(username, password));
|
new UsernamePasswordCredentials(username, password));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
httpClient.getParams().setParameter("http.socket.timeout", Util.getNetworkTimeout(context));
|
||||||
|
|
||||||
HttpResponse response = httpClient.execute(request, httpContext);
|
HttpResponse response = httpClient.execute(request, httpContext);
|
||||||
detectRedirect(originalUrl, context, httpContext);
|
detectRedirect(originalUrl, context, httpContext);
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -74,6 +74,8 @@ public final class Constants {
|
||||||
public static final String PREFERENCES_KEY_SCROBBLE = "scrobble";
|
public static final String PREFERENCES_KEY_SCROBBLE = "scrobble";
|
||||||
public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode";
|
public static final String PREFERENCES_KEY_REPEAT_MODE = "repeatMode";
|
||||||
public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload";
|
public static final String PREFERENCES_KEY_WIFI_REQUIRED_FOR_DOWNLOAD = "wifiRequiredForDownload";
|
||||||
|
public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength";
|
||||||
|
public static final String PREFERENCES_KEY_NETWORK_TIMEOUT = "networkTimeout";
|
||||||
|
|
||||||
// Name of the preferences file.
|
// Name of the preferences file.
|
||||||
public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.androidapp_preferences";
|
public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.androidapp_preferences";
|
||||||
|
|
|
@ -806,4 +806,14 @@ public class Util extends DownloadActivity {
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getNetworkTimeout(Context context) {
|
||||||
|
SharedPreferences prefs = getPreferences(context);
|
||||||
|
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT, "15000"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getBufferLength(Context context) {
|
||||||
|
SharedPreferences prefs = getPreferences(context);
|
||||||
|
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_BUFFER_LENGTH, "5"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue