Variable speed playback as user preferences and customization of playback speed.
This commit is contained in:
parent
b48c3807fd
commit
916074957f
@ -40,15 +40,25 @@
|
|||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="playback_speed_values">
|
<string-array name="playback_speed_values">
|
||||||
<item>1.0</item>
|
<item>1.0</item>
|
||||||
|
<item>1.05</item>
|
||||||
<item>1.10</item>
|
<item>1.10</item>
|
||||||
|
<item>1.15</item>
|
||||||
<item>1.20</item>
|
<item>1.20</item>
|
||||||
|
<item>1.25</item>
|
||||||
<item>1.30</item>
|
<item>1.30</item>
|
||||||
|
<item>1.35</item>
|
||||||
<item>1.40</item>
|
<item>1.40</item>
|
||||||
|
<item>1.45</item>
|
||||||
<item>1.50</item>
|
<item>1.50</item>
|
||||||
|
<item>1.55</item>
|
||||||
<item>1.60</item>
|
<item>1.60</item>
|
||||||
|
<item>1.65</item>
|
||||||
<item>1.70</item>
|
<item>1.70</item>
|
||||||
|
<item>1.75</item>
|
||||||
<item>1.80</item>
|
<item>1.80</item>
|
||||||
|
<item>1.85</item>
|
||||||
<item>1.90</item>
|
<item>1.90</item>
|
||||||
|
<item>1.95</item>
|
||||||
<item>2.0</item>
|
<item>2.0</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@
|
|||||||
<string name="download_plugin_label">Download Plugin</string>
|
<string name="download_plugin_label">Download Plugin</string>
|
||||||
<string name="no_playback_plugin_title">Plugin Not Installed</string>
|
<string name="no_playback_plugin_title">Plugin Not Installed</string>
|
||||||
<string name="no_playback_plugin_msg">For variable speed playback to work, a third party library must be installed.\n\nTap \'Download Plugin\' to download a free plugin from the Play Store\n\nAny problems found using this plugin are not the responsibility of AntennaPod and should be reported to the plugin owner.</string>
|
<string name="no_playback_plugin_msg">For variable speed playback to work, a third party library must be installed.\n\nTap \'Download Plugin\' to download a free plugin from the Play Store\n\nAny problems found using this plugin are not the responsibility of AntennaPod and should be reported to the plugin owner.</string>
|
||||||
<string name="set_playback_speed_label">Playback Speed</string>
|
<string name="set_playback_speed_label">Playback Speeds</string>
|
||||||
|
|
||||||
<!-- Empty list labels -->
|
<!-- Empty list labels -->
|
||||||
<string name="no_items_label">There are no items in this list.</string>
|
<string name="no_items_label">There are no items in this list.</string>
|
||||||
@ -193,8 +193,8 @@
|
|||||||
<string name="pref_update_interval_hours_plural">hours</string>
|
<string name="pref_update_interval_hours_plural">hours</string>
|
||||||
<string name="pref_update_interval_hours_singular">hour</string>
|
<string name="pref_update_interval_hours_singular">hour</string>
|
||||||
<string name="pref_update_interval_hours_manual">Manual</string>
|
<string name="pref_update_interval_hours_manual">Manual</string>
|
||||||
<string name="pref_playback_speed_title">Playback Speed</string>
|
<string name="pref_playback_speed_title">Playback Speeds</string>
|
||||||
<string name="pref_playback_speed_sum">Change the speed of audio playback using a 3rd party control</string>
|
<string name="pref_playback_speed_sum">Customize the speeds available for variable speed audio playback</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- Search -->
|
<!-- Search -->
|
||||||
|
@ -10,6 +10,7 @@ import android.support.v4.app.FragmentTransaction;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.View.OnLongClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
@ -24,11 +25,13 @@ import de.danoeh.antennapod.AppConfig;
|
|||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.adapter.ChapterListAdapter;
|
import de.danoeh.antennapod.adapter.ChapterListAdapter;
|
||||||
import de.danoeh.antennapod.asynctask.ImageLoader;
|
import de.danoeh.antennapod.asynctask.ImageLoader;
|
||||||
|
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
|
||||||
import de.danoeh.antennapod.feed.Chapter;
|
import de.danoeh.antennapod.feed.Chapter;
|
||||||
import de.danoeh.antennapod.feed.MediaType;
|
import de.danoeh.antennapod.feed.MediaType;
|
||||||
import de.danoeh.antennapod.feed.SimpleChapter;
|
import de.danoeh.antennapod.feed.SimpleChapter;
|
||||||
import de.danoeh.antennapod.fragment.CoverFragment;
|
import de.danoeh.antennapod.fragment.CoverFragment;
|
||||||
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
|
import de.danoeh.antennapod.fragment.ItemDescriptionFragment;
|
||||||
|
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.service.PlaybackService;
|
import de.danoeh.antennapod.service.PlaybackService;
|
||||||
import de.danoeh.antennapod.util.playback.ExternalMedia;
|
import de.danoeh.antennapod.util.playback.ExternalMedia;
|
||||||
import de.danoeh.antennapod.util.playback.Playable;
|
import de.danoeh.antennapod.util.playback.Playable;
|
||||||
@ -400,27 +403,45 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final double PLAYBACK_SPEED_STEP = 0.5;
|
|
||||||
final double PLAYBACK_SPEED_MAX = 2.0;
|
|
||||||
final double PLAYBACK_SPEED_DEFAULT = 1.0;
|
|
||||||
|
|
||||||
if (controller != null && controller.canSetPlaybackSpeed()) {
|
if (controller != null && controller.canSetPlaybackSpeed()) {
|
||||||
double currentPlaybackSpeed = controller
|
String[] availableSpeeds = UserPreferences
|
||||||
.getCurrentPlaybackSpeedMultiplier();
|
.getPlaybackSpeedArray();
|
||||||
if (currentPlaybackSpeed != -1) {
|
String currentSpeed = UserPreferences.getPlaybackSpeed();
|
||||||
if (currentPlaybackSpeed >= PLAYBACK_SPEED_MAX) {
|
|
||||||
controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT);
|
// Provide initial value in case the speed list has changed
|
||||||
} else {
|
// out from under us
|
||||||
controller.setPlaybackSpeed(currentPlaybackSpeed
|
// and our current speed isn't in the new list
|
||||||
+ PLAYBACK_SPEED_STEP);
|
String newSpeed;
|
||||||
}
|
if (availableSpeeds.length > 0) {
|
||||||
|
newSpeed = availableSpeeds[0];
|
||||||
} else {
|
} else {
|
||||||
controller.setPlaybackSpeed(PLAYBACK_SPEED_DEFAULT);
|
newSpeed = "1.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < availableSpeeds.length; i++) {
|
||||||
|
if (availableSpeeds[i].equals(currentSpeed)) {
|
||||||
|
if (i == availableSpeeds.length - 1) {
|
||||||
|
newSpeed = availableSpeeds[0];
|
||||||
|
} else {
|
||||||
|
newSpeed = availableSpeeds[i + 1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UserPreferences.setPlaybackSpeed(AudioplayerActivity.this,
|
||||||
|
newSpeed);
|
||||||
|
controller.setPlaybackSpeed(Float.parseFloat(newSpeed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
butPlaybackSpeed.setOnLongClickListener(new OnLongClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
VariableSpeedDialog.showDialog(AudioplayerActivity.this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -430,14 +451,12 @@ public class AudioplayerActivity extends MediaplayerActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateButPlaybackSpeed() {
|
private void updateButPlaybackSpeed() {
|
||||||
double playbackSpeed;
|
|
||||||
if (controller == null
|
if (controller == null
|
||||||
|| (playbackSpeed = controller
|
|| (controller.getCurrentPlaybackSpeedMultiplier() == -1)) {
|
||||||
.getCurrentPlaybackSpeedMultiplier()) == -1) {
|
|
||||||
butPlaybackSpeed.setVisibility(View.GONE);
|
butPlaybackSpeed.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
butPlaybackSpeed.setVisibility(View.VISIBLE);
|
butPlaybackSpeed.setVisibility(View.VISIBLE);
|
||||||
butPlaybackSpeed.setText(String.format("%.1fx", playbackSpeed));
|
butPlaybackSpeed.setText(UserPreferences.getPlaybackSpeed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,9 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources.Theme;
|
import android.content.res.Resources.Theme;
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
@ -29,7 +27,7 @@ import de.danoeh.antennapod.AppConfig;
|
|||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
import de.danoeh.antennapod.asynctask.FlattrClickWorker;
|
||||||
import de.danoeh.antennapod.asynctask.OpmlExportWorker;
|
import de.danoeh.antennapod.asynctask.OpmlExportWorker;
|
||||||
import de.danoeh.antennapod.dialog.GetSpeedPlaybackPlugin;
|
import de.danoeh.antennapod.dialog.VariableSpeedDialog;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
import de.danoeh.antennapod.preferences.UserPreferences;
|
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||||
import de.danoeh.antennapod.util.flattr.FlattrUtils;
|
import de.danoeh.antennapod.util.flattr.FlattrUtils;
|
||||||
@ -175,7 +173,7 @@ public class PreferenceActivity extends SherlockPreferenceActivity {
|
|||||||
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
.setOnPreferenceClickListener(new OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
setPlaybackSpeed();
|
VariableSpeedDialog.showDialog(PreferenceActivity.this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -264,40 +262,6 @@ public class PreferenceActivity extends SherlockPreferenceActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPlaybackSpeed() {
|
|
||||||
if (com.aocate.media.MediaPlayer
|
|
||||||
.isPrestoLibraryInstalled(PreferenceActivity.this)) {
|
|
||||||
int currentIndex = 0;
|
|
||||||
final String[] speedValues = getResources().getStringArray(
|
|
||||||
R.array.playback_speed_values);
|
|
||||||
for (int i = 0; i < speedValues.length; i++) {
|
|
||||||
// Probably shouldn't float compare here...
|
|
||||||
if (Float.parseFloat(speedValues[i]) == UserPreferences
|
|
||||||
.getPlaybackSpeed()) {
|
|
||||||
currentIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(
|
|
||||||
PreferenceActivity.this);
|
|
||||||
builder.setTitle(R.string.set_playback_speed_label);
|
|
||||||
builder.setSingleChoiceItems(R.array.playback_speed_values,
|
|
||||||
currentIndex, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
UserPreferences.setPlaybackSpeed(
|
|
||||||
PreferenceActivity.this,
|
|
||||||
Float.valueOf(speedValues[which]));
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.create().show();
|
|
||||||
|
|
||||||
} else {
|
|
||||||
GetSpeedPlaybackPlugin.showDialog(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package de.danoeh.antennapod.dialog;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import de.danoeh.antennapod.R;
|
|
||||||
|
|
||||||
public class GetSpeedPlaybackPlugin {
|
|
||||||
private GetSpeedPlaybackPlugin() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void showDialog(final Context context) {
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
|
||||||
builder.setTitle(R.string.no_playback_plugin_title);
|
|
||||||
builder.setMessage(R.string.no_playback_plugin_msg);
|
|
||||||
builder.setNegativeButton(R.string.close_label, null);
|
|
||||||
builder.setPositiveButton(R.string.download_plugin_label,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
Intent playStoreIntent = new Intent(
|
|
||||||
Intent.ACTION_VIEW,
|
|
||||||
Uri.parse("market://details?id=com.falconware.prestissimo"));
|
|
||||||
context.startActivity(playStoreIntent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.create().show();
|
|
||||||
}
|
|
||||||
}
|
|
95
src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java
Normal file
95
src/de/danoeh/antennapod/dialog/VariableSpeedDialog.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
package de.danoeh.antennapod.dialog;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import de.danoeh.antennapod.R;
|
||||||
|
import de.danoeh.antennapod.preferences.UserPreferences;
|
||||||
|
|
||||||
|
public class VariableSpeedDialog {
|
||||||
|
private VariableSpeedDialog() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showDialog(final Context context) {
|
||||||
|
if (com.aocate.media.MediaPlayer.isPrestoLibraryInstalled(context)) {
|
||||||
|
showSpeedSelectorDialog(context);
|
||||||
|
} else {
|
||||||
|
showGetPluginDialog(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showGetPluginDialog(final Context context) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(R.string.no_playback_plugin_title);
|
||||||
|
builder.setMessage(R.string.no_playback_plugin_msg);
|
||||||
|
builder.setNegativeButton(R.string.close_label, null);
|
||||||
|
builder.setPositiveButton(R.string.download_plugin_label,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
Intent playStoreIntent = new Intent(
|
||||||
|
Intent.ACTION_VIEW,
|
||||||
|
Uri.parse("market://details?id=com.falconware.prestissimo"));
|
||||||
|
context.startActivity(playStoreIntent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showSpeedSelectorDialog(final Context context) {
|
||||||
|
final String[] speedValues = context.getResources().getStringArray(
|
||||||
|
R.array.playback_speed_values);
|
||||||
|
// According to Java spec these get initialized to false on creation
|
||||||
|
final boolean[] speedChecked = new boolean[speedValues.length];
|
||||||
|
|
||||||
|
// Build the "isChecked" array so that multiChoice dialog is
|
||||||
|
// populated correctly
|
||||||
|
List<String> selectedSpeedList = Arrays.asList(UserPreferences
|
||||||
|
.getPlaybackSpeedArray());
|
||||||
|
for (int i = 0; i < speedValues.length; i++) {
|
||||||
|
speedChecked[i] = selectedSpeedList.contains(speedValues[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(R.string.set_playback_speed_label);
|
||||||
|
builder.setMultiChoiceItems(R.array.playback_speed_values,
|
||||||
|
speedChecked, new DialogInterface.OnMultiChoiceClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which,
|
||||||
|
boolean isChecked) {
|
||||||
|
speedChecked[which] = isChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
builder.setNegativeButton(android.R.string.cancel, null);
|
||||||
|
builder.setPositiveButton(android.R.string.ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
int choiceCount = 0;
|
||||||
|
for (int i = 0; i < speedChecked.length; i++) {
|
||||||
|
if (speedChecked[i]) {
|
||||||
|
choiceCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String[] newSpeedValues = new String[choiceCount];
|
||||||
|
int newSpeedIndex = 0;
|
||||||
|
for (int i = 0; i < speedChecked.length; i++) {
|
||||||
|
if (speedChecked[i]) {
|
||||||
|
newSpeedValues[newSpeedIndex++] = speedValues[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UserPreferences.setPlaybackSpeedArray(context,
|
||||||
|
newSpeedValues);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.create().show();
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@ import java.io.IOException;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@ -17,7 +19,6 @@ import de.danoeh.antennapod.AppConfig;
|
|||||||
import de.danoeh.antennapod.R;
|
import de.danoeh.antennapod.R;
|
||||||
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
|
import de.danoeh.antennapod.activity.OpmlImportFromPathActivity;
|
||||||
import de.danoeh.antennapod.receiver.FeedUpdateReceiver;
|
import de.danoeh.antennapod.receiver.FeedUpdateReceiver;
|
||||||
import de.danoeh.antennapod.service.PlaybackService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to preferences set by the user in the settings screen. A
|
* Provides access to preferences set by the user in the settings screen. A
|
||||||
@ -43,6 +44,7 @@ public class UserPreferences implements
|
|||||||
private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
|
private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks";
|
||||||
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
|
public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize";
|
||||||
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
|
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
|
||||||
|
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
|
||||||
|
|
||||||
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
|
private static int EPISODE_CACHE_SIZE_UNLIMITED = -1;
|
||||||
|
|
||||||
@ -62,7 +64,8 @@ public class UserPreferences implements
|
|||||||
private boolean enableAutodownloadWifiFilter;
|
private boolean enableAutodownloadWifiFilter;
|
||||||
private String[] autodownloadSelectedNetworks;
|
private String[] autodownloadSelectedNetworks;
|
||||||
private int episodeCacheSize;
|
private int episodeCacheSize;
|
||||||
private float playbackSpeed;
|
private String playbackSpeed;
|
||||||
|
private String[] playbackSpeedArray;
|
||||||
|
|
||||||
private UserPreferences(Context context) {
|
private UserPreferences(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@ -111,7 +114,9 @@ public class UserPreferences implements
|
|||||||
episodeCacheSize = readEpisodeCacheSize(sp.getString(
|
episodeCacheSize = readEpisodeCacheSize(sp.getString(
|
||||||
PREF_EPISODE_CACHE_SIZE, "20"));
|
PREF_EPISODE_CACHE_SIZE, "20"));
|
||||||
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
|
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
|
||||||
playbackSpeed = sp.getFloat(PREF_PLAYBACK_SPEED, (float) 1.0);
|
playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
|
||||||
|
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
|
||||||
|
PREF_PLAYBACK_SPEED_ARRAY, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int readThemeValue(String valueFromPrefs) {
|
private int readThemeValue(String valueFromPrefs) {
|
||||||
@ -139,6 +144,28 @@ public class UserPreferences implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] readPlaybackSpeedArray(String valueFromPrefs) {
|
||||||
|
String[] playbackSpeeds = null;
|
||||||
|
// If this preference hasn't been set yet, return all options
|
||||||
|
if (valueFromPrefs == null) {
|
||||||
|
playbackSpeeds = context.getResources().getStringArray(
|
||||||
|
R.array.playback_speed_values);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
JSONArray jsonArray = new JSONArray(valueFromPrefs);
|
||||||
|
playbackSpeeds = new String[jsonArray.length()];
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++) {
|
||||||
|
playbackSpeeds[i] = jsonArray.getString(i);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.e(TAG,
|
||||||
|
"Got JSON error when trying to get speeds from JSONArray");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return playbackSpeeds;
|
||||||
|
}
|
||||||
|
|
||||||
private static void instanceAvailable() {
|
private static void instanceAvailable() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
@ -200,11 +227,16 @@ public class UserPreferences implements
|
|||||||
return EPISODE_CACHE_SIZE_UNLIMITED;
|
return EPISODE_CACHE_SIZE_UNLIMITED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float getPlaybackSpeed() {
|
public static String getPlaybackSpeed() {
|
||||||
instanceAvailable();
|
instanceAvailable();
|
||||||
return instance.playbackSpeed;
|
return instance.playbackSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] getPlaybackSpeedArray() {
|
||||||
|
instanceAvailable();
|
||||||
|
return instance.playbackSpeedArray;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the capacity of the episode cache. This method will return the
|
* Returns the capacity of the episode cache. This method will return the
|
||||||
* negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to
|
* negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to
|
||||||
@ -260,20 +292,31 @@ public class UserPreferences implements
|
|||||||
} else if (key.equals(PREF_ENABLE_AUTODL)) {
|
} else if (key.equals(PREF_ENABLE_AUTODL)) {
|
||||||
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
|
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
|
||||||
} else if (key.equals(PREF_PLAYBACK_SPEED)) {
|
} else if (key.equals(PREF_PLAYBACK_SPEED)) {
|
||||||
playbackSpeed = sp.getFloat(PREF_PLAYBACK_SPEED, (float) 1.0);
|
playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
|
||||||
|
} else if (key.equals(PREF_PLAYBACK_SPEED_ARRAY)) {
|
||||||
|
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
|
||||||
|
PREF_PLAYBACK_SPEED_ARRAY, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPlaybackSpeed(Context context, float speed) {
|
public static void setPlaybackSpeed(Context context, String speed) {
|
||||||
SharedPreferences prefs = PreferenceManager
|
SharedPreferences prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(context.getApplicationContext());
|
.getDefaultSharedPreferences(context.getApplicationContext());
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putFloat(PREF_PLAYBACK_SPEED, speed);
|
editor.putString(PREF_PLAYBACK_SPEED, speed);
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
Intent intent = new Intent(context, PlaybackService.class);
|
public static void setPlaybackSpeedArray(Context context, String[] speeds) {
|
||||||
intent.putExtra(PlaybackService.EXTRA_PLAYBACK_SPEED, speed);
|
SharedPreferences prefs = PreferenceManager
|
||||||
context.startService(intent);
|
.getDefaultSharedPreferences(context.getApplicationContext());
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
for (String speed : speeds) {
|
||||||
|
jsonArray.put(speed);
|
||||||
|
}
|
||||||
|
editor.putString(PREF_PLAYBACK_SPEED_ARRAY, jsonArray.toString());
|
||||||
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setAutodownloadSelectedNetworks(Context context,
|
public static void setAutodownloadSelectedNetworks(Context context,
|
||||||
|
@ -82,7 +82,6 @@ public class PlaybackService extends Service {
|
|||||||
public static final String ACTION_PLAYER_NOTIFICATION = "action.de.danoeh.antennapod.service.playerNotification";
|
public static final String ACTION_PLAYER_NOTIFICATION = "action.de.danoeh.antennapod.service.playerNotification";
|
||||||
public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.service.notificationCode";
|
public static final String EXTRA_NOTIFICATION_CODE = "extra.de.danoeh.antennapod.service.notificationCode";
|
||||||
public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.service.notificationType";
|
public static final String EXTRA_NOTIFICATION_TYPE = "extra.de.danoeh.antennapod.service.notificationType";
|
||||||
public static final String EXTRA_PLAYBACK_SPEED = "extra.de.danoeh.antennapod.service.playbackSpeed";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the PlaybackService receives this action, it will stop playback and
|
* If the PlaybackService receives this action, it will stop playback and
|
||||||
@ -373,17 +372,10 @@ public class PlaybackService extends Service {
|
|||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "OnStartCommand called");
|
Log.d(TAG, "OnStartCommand called");
|
||||||
int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
||||||
float playbackSpeed = intent.getFloatExtra(EXTRA_PLAYBACK_SPEED, -1);
|
|
||||||
if (keycode != -1) {
|
if (keycode != -1) {
|
||||||
if (AppConfig.DEBUG)
|
if (AppConfig.DEBUG)
|
||||||
Log.d(TAG, "Received media button event");
|
Log.d(TAG, "Received media button event");
|
||||||
handleKeycode(keycode);
|
handleKeycode(keycode);
|
||||||
} else if (playbackSpeed > 0) {
|
|
||||||
if (media == null) {
|
|
||||||
stopSelf();
|
|
||||||
} else {
|
|
||||||
setSpeed(playbackSpeed);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
||||||
@ -988,7 +980,7 @@ public class PlaybackService extends Service {
|
|||||||
Log.d(TAG, "Resuming/Starting playback");
|
Log.d(TAG, "Resuming/Starting playback");
|
||||||
writePlaybackPreferences();
|
writePlaybackPreferences();
|
||||||
|
|
||||||
setSpeed(UserPreferences.getPlaybackSpeed());
|
setSpeed(Float.parseFloat(UserPreferences.getPlaybackSpeed()));
|
||||||
player.start();
|
player.start();
|
||||||
if (status != PlayerStatus.PAUSED) {
|
if (status != PlayerStatus.PAUSED) {
|
||||||
player.seekTo(media.getPosition());
|
player.seekTo(media.getPosition());
|
||||||
@ -1569,7 +1561,7 @@ public class PlaybackService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getCurrentPlaybackSpeed() {
|
public float getCurrentPlaybackSpeed() {
|
||||||
if (media.getMediaType() == MediaType.AUDIO
|
if (media.getMediaType() == MediaType.AUDIO
|
||||||
&& player instanceof AudioPlayer) {
|
&& player instanceof AudioPlayer) {
|
||||||
AudioPlayer audioPlayer = (AudioPlayer) player;
|
AudioPlayer audioPlayer = (AudioPlayer) player;
|
||||||
|
@ -255,7 +255,8 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
public abstract void onPositionObserverUpdate();
|
public abstract void onPositionObserverUpdate();
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
private final ServiceConnection mConnection = new ServiceConnection() {
|
||||||
|
@Override
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
public void onServiceConnected(ComponentName className, IBinder service) {
|
||||||
playbackService = ((PlaybackService.LocalBinder) service)
|
playbackService = ((PlaybackService.LocalBinder) service)
|
||||||
.getService();
|
.getService();
|
||||||
@ -343,7 +344,7 @@ public abstract class PlaybackController {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -356,7 +357,7 @@ public abstract class PlaybackController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public abstract void onPlaybackSpeedChange();
|
public abstract void onPlaybackSpeedChange();
|
||||||
|
|
||||||
public abstract void onShutdownNotification();
|
public abstract void onShutdownNotification();
|
||||||
@ -662,13 +663,13 @@ public abstract class PlaybackController {
|
|||||||
return playbackService != null && playbackService.canSetSpeed();
|
return playbackService != null && playbackService.canSetSpeed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlaybackSpeed(double speed) {
|
public void setPlaybackSpeed(float speed) {
|
||||||
if (playbackService != null) {
|
if (playbackService != null) {
|
||||||
playbackService.setSpeed(speed);
|
playbackService.setSpeed(speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getCurrentPlaybackSpeedMultiplier() {
|
public float getCurrentPlaybackSpeedMultiplier() {
|
||||||
if (canSetPlaybackSpeed()) {
|
if (canSetPlaybackSpeed()) {
|
||||||
return playbackService.getCurrentPlaybackSpeed();
|
return playbackService.getCurrentPlaybackSpeed();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user