Changed type of media last playback speed to float from string

Also sets default to "magic" -1 value
This commit is contained in:
Jonas Kalderstam 2019-09-13 00:16:22 +02:00
parent 00c1e7a3d3
commit 4746b16b12
10 changed files with 73 additions and 40 deletions

View File

@ -152,7 +152,11 @@ public class AudioplayerActivity extends MediaplayerInfoActivity {
private void storeNewMediaPlaybackSpeed(String speed) {
Playable media = controller.getMedia();
if (media instanceof FeedMedia) {
((FeedMedia) media).updateLastPlaybackSpeed(speed);
try {
((FeedMedia) media).updateLastPlaybackSpeed(Float.parseFloat(speed));
} catch (NumberFormatException e) {
// Well this was awkward...
}
}
}
}

View File

@ -64,6 +64,8 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
/**
* Provides general features which are both needed for playing audio and video
@ -873,16 +875,21 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements
}
}
protected float getPlaybackSpeedForMedia() {
float getPlaybackSpeedForMedia() {
float playbackSpeed = SPEED_USE_GLOBAL;
if (controller != null) {
Playable media = controller.getMedia();
boolean isFeedMedia = media instanceof FeedMedia;
if (isFeedMedia) {
return ((FeedMedia) media).getMediaPlaybackSpeed();
playbackSpeed = ((FeedMedia) media).getMediaPlaybackSpeed();
}
}
return UserPreferences.getPlaybackSpeed();
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed();
}
return playbackSpeed;
}
}

View File

@ -20,6 +20,8 @@ import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
public class PlaybackControlsDialog extends DialogFragment {
private static final float PLAYBACK_SPEED_STEP = 0.05f;
private static final float DEFAULT_MIN_PLAYBACK_SPEED = 0.5f;
@ -214,15 +216,20 @@ public class PlaybackControlsDialog extends DialogFragment {
return UserPreferences.getVideoPlaybackSpeed();
}
float playbackSpeed = SPEED_USE_GLOBAL;
if (controller != null) {
Playable media = controller.getMedia();
boolean isFeedMedia = media instanceof FeedMedia;
if (isFeedMedia) {
return ((FeedMedia) media).getMediaPlaybackSpeed();
playbackSpeed = ((FeedMedia) media).getMediaPlaybackSpeed();
}
}
return UserPreferences.getPlaybackSpeed();
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed();
}
return playbackSpeed;
}
}

View File

@ -63,6 +63,7 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
import static de.danoeh.antennapod.dialog.EpisodesApplyActionFragment.ACTION_DELETE;
import static de.danoeh.antennapod.dialog.EpisodesApplyActionFragment.ACTION_REMOVE_FROM_QUEUE;
@ -600,6 +601,9 @@ public class QueueFragment extends Fragment {
long timeLeft = 0;
for(FeedItem item : queue) {
float playbackSpeed = item.getFeedPlaybackSpeed();
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed();
}
if(item.getMedia() != null) {
timeLeft +=
(long) ((item.getMedia().getDuration() - item.getMedia().getPosition())

View File

@ -20,6 +20,8 @@ import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.ShownotesProvider;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
/**
* Data Object for a XML message
*
@ -493,6 +495,6 @@ public class FeedItem extends FeedComponent implements ShownotesProvider, ImageR
if (feed != null) {
return feed.getPreferences().getCurrentPlaybackSpeed();
}
return UserPreferences.getPlaybackSpeed();
return SPEED_USE_GLOBAL;
}
}

View File

@ -21,15 +21,18 @@ import de.danoeh.antennapod.core.preferences.PlaybackPreferences;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.PodDBAdapter;
import de.danoeh.antennapod.core.util.ChapterUtils;
import de.danoeh.antennapod.core.util.playback.Playable;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
public class FeedMedia extends FeedFile implements Playable {
private static final String TAG = "FeedMedia";
public static final float LAST_PLAYBACK_SPEED_UNSET = SPEED_USE_GLOBAL;
public static final int FEEDFILETYPE_FEEDMEDIA = 2;
public static final int PLAYABLE_TYPE_FEEDMEDIA = 1;
@ -55,7 +58,7 @@ public class FeedMedia extends FeedFile implements Playable {
private Date playbackCompletionDate;
private int startPosition = -1;
private int playedDurationWhenStarted;
private String lastPlaybackSpeed = null;
private float lastPlaybackSpeed = LAST_PLAYBACK_SPEED_UNSET;
// if null: unknown, will be checked
private Boolean hasEmbeddedPicture;
@ -92,7 +95,7 @@ public class FeedMedia extends FeedFile implements Playable {
private FeedMedia(long id, FeedItem item, int duration, int position,
long size, String mime_type, String file_url, String download_url,
boolean downloaded, Date playbackCompletionDate, int played_duration,
Boolean hasEmbeddedPicture, long lastPlayedTime, String lastPlaybackSpeed) {
Boolean hasEmbeddedPicture, long lastPlayedTime, float lastPlaybackSpeed) {
this(id, item, duration, position, size, mime_type, file_url, download_url, downloaded,
playbackCompletionDate, played_duration, lastPlayedTime);
this.hasEmbeddedPicture = hasEmbeddedPicture;
@ -111,7 +114,7 @@ public class FeedMedia extends FeedFile implements Playable {
int indexDownloaded = cursor.getColumnIndex(PodDBAdapter.KEY_DOWNLOADED);
int indexPlayedDuration = cursor.getColumnIndex(PodDBAdapter.KEY_PLAYED_DURATION);
int indexLastPlayedTime = cursor.getColumnIndex(PodDBAdapter.KEY_LAST_PLAYED_TIME);
int indexLastPlaybackSpeed = cursor.getColumnIndex(PodDBAdapter.KEY_LAST_PLAYBACK_SPEED);
int indexLastPlaybackSpeed = cursor.getColumnIndex(PodDBAdapter.KEY_MEDIA_LAST_PLAYBACK_SPEED);
long mediaId = cursor.getLong(indexId);
Date playbackCompletionDate = null;
@ -147,7 +150,7 @@ public class FeedMedia extends FeedFile implements Playable {
cursor.getInt(indexPlayedDuration),
hasEmbeddedPicture,
cursor.getLong(indexLastPlayedTime),
cursor.getString(indexLastPlaybackSpeed)
cursor.getFloat(indexLastPlaybackSpeed)
);
}
@ -628,11 +631,11 @@ public class FeedMedia extends FeedFile implements Playable {
return super.equals(o);
}
public String getLastPlaybackSpeed() {
public float getLastPlaybackSpeed() {
return lastPlaybackSpeed;
}
public void updateLastPlaybackSpeed(String newSpeed) {
public void updateLastPlaybackSpeed(float newSpeed) {
lastPlaybackSpeed = newSpeed;
DBWriter.setFeedMediaPlaybackInformation(this);
}
@ -642,19 +645,15 @@ public class FeedMedia extends FeedFile implements Playable {
* @return the current playback speed for the media, or the feed's configured speed
*/
public float getMediaPlaybackSpeed() {
if (lastPlaybackSpeed != null) {
try {
return Float.parseFloat(lastPlaybackSpeed);
} catch (NumberFormatException e) {
lastPlaybackSpeed = null;
float playbackSpeed = lastPlaybackSpeed;
if (playbackSpeed == LAST_PLAYBACK_SPEED_UNSET) {
FeedItem item = getItem();
if (item != null) {
playbackSpeed = item.getFeedPlaybackSpeed();
}
}
FeedItem item = getItem();
if (item != null) {
return item.getFeedPlaybackSpeed();
}
return UserPreferences.getPlaybackSpeed();
return playbackSpeed;
}
}

View File

@ -14,6 +14,8 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter;
*/
public class FeedPreferences {
public static final float SPEED_USE_GLOBAL = -1;
@NonNull
private FeedFilter filter;
private long feedID;
@ -180,7 +182,7 @@ public class FeedPreferences {
this.password = password;
}
public float getCurrentPlaybackSpeed() {
float getCurrentPlaybackSpeed() {
float speed = 0.0f;
if (!"global".equals(feedPlaybackSpeed)) {
@ -193,7 +195,7 @@ public class FeedPreferences {
// Either global or error happened
if (speed == 0.0f) {
speed = UserPreferences.getPlaybackSpeed();
speed = SPEED_USE_GLOBAL;
}
return speed;

View File

@ -35,6 +35,8 @@ import de.danoeh.antennapod.core.util.playback.IPlayer;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.VideoPlayer;
import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL;
/**
* Manages the MediaPlayer object of the PlaybackService.
*/
@ -305,13 +307,18 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
Log.d(TAG, "Audiofocus successfully requested");
Log.d(TAG, "Resuming/Starting playback");
acquireWifiLockIfNecessary();
float playbackSpeed;
if (media.getMediaType() == MediaType.VIDEO) {
setPlaybackParams(UserPreferences.getVideoPlaybackSpeed(), UserPreferences.isSkipSilence());
playbackSpeed = UserPreferences.getVideoPlaybackSpeed();
} else if (media instanceof FeedMedia) {
setPlaybackParams(((FeedMedia) media).getMediaPlaybackSpeed(), UserPreferences.isSkipSilence());
playbackSpeed = ((FeedMedia) media).getMediaPlaybackSpeed();
} else {
setPlaybackParams(UserPreferences.getPlaybackSpeed(), UserPreferences.isSkipSilence());
playbackSpeed = SPEED_USE_GLOBAL;
}
if (playbackSpeed == SPEED_USE_GLOBAL) {
playbackSpeed = UserPreferences.getPlaybackSpeed();
}
setPlaybackParams(playbackSpeed, UserPreferences.isSkipSilence());
setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {

View File

@ -8,6 +8,8 @@ import android.util.Log;
import de.danoeh.antennapod.core.feed.FeedItem;
import static de.danoeh.antennapod.core.feed.FeedMedia.LAST_PLAYBACK_SPEED_UNSET;
class DBUpgrader {
/**
* Upgrades the given database to a new schema version
@ -292,7 +294,7 @@ class DBUpgrader {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_FEED_PLAYBACK_SPEED + " TEXT");
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEED_MEDIA
+ " ADD COLUMN " + PodDBAdapter.KEY_LAST_PLAYBACK_SPEED + " TEXT");
+ " ADD COLUMN " + PodDBAdapter.KEY_MEDIA_LAST_PLAYBACK_SPEED + " REAL DEFAULT " + LAST_PLAYBACK_SPEED_UNSET);
}
}

View File

@ -12,10 +12,7 @@ import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
@ -40,6 +37,8 @@ import de.danoeh.antennapod.core.service.download.DownloadStatus;
import de.danoeh.antennapod.core.util.LongIntMap;
import org.greenrobot.eventbus.EventBus;
import static de.danoeh.antennapod.core.feed.FeedMedia.LAST_PLAYBACK_SPEED_UNSET;
// TODO Remove media column from feeditem table
/**
@ -115,7 +114,7 @@ public class PodDBAdapter {
public static final String KEY_INCLUDE_FILTER = "include_filter";
public static final String KEY_EXCLUDE_FILTER = "exclude_filter";
public static final String KEY_FEED_PLAYBACK_SPEED = "feed_playback_speed";
public static final String KEY_LAST_PLAYBACK_SPEED = "last_playback_speed";
public static final String KEY_MEDIA_LAST_PLAYBACK_SPEED = "last_playback_speed";
// Table names
static final String TABLE_NAME_FEEDS = "Feeds";
@ -171,7 +170,7 @@ public class PodDBAdapter {
+ KEY_PLAYED_DURATION + " INTEGER,"
+ KEY_HAS_EMBEDDED_PICTURE + " INTEGER,"
+ KEY_LAST_PLAYED_TIME + " INTEGER,"
+ KEY_LAST_PLAYBACK_SPEED + " TEXT)";
+ KEY_MEDIA_LAST_PLAYBACK_SPEED + " REAL)";
private static final String CREATE_TABLE_DOWNLOAD_LOG = "CREATE TABLE "
+ TABLE_NAME_DOWNLOAD_LOG + " (" + TABLE_PRIMARY_KEY + KEY_FEEDFILE
@ -442,7 +441,7 @@ public class PodDBAdapter {
values.put(KEY_FILE_URL, media.getFile_url());
values.put(KEY_HAS_EMBEDDED_PICTURE, media.hasEmbeddedPicture());
values.put(KEY_LAST_PLAYED_TIME, media.getLastPlayedTime());
values.put(KEY_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
values.put(KEY_MEDIA_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
if (media.getPlaybackCompletionDate() != null) {
values.put(KEY_PLAYBACK_COMPLETION_DATE, media.getPlaybackCompletionDate().getTime());
@ -468,7 +467,7 @@ public class PodDBAdapter {
values.put(KEY_DURATION, media.getDuration());
values.put(KEY_PLAYED_DURATION, media.getPlayedDuration());
values.put(KEY_LAST_PLAYED_TIME, media.getLastPlayedTime());
values.put(KEY_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
values.put(KEY_MEDIA_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",
new String[]{String.valueOf(media.getId())});
} else {
@ -479,7 +478,7 @@ public class PodDBAdapter {
public void setFeedMediaLastPlaybackSpeed(FeedMedia media) {
if (media.getId() != 0) {
ContentValues values = new ContentValues();
values.put(KEY_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
values.put(KEY_MEDIA_LAST_PLAYBACK_SPEED, media.getLastPlaybackSpeed());
db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",
new String[]{String.valueOf(media.getId())});
} else {
@ -493,7 +492,7 @@ public class PodDBAdapter {
values.put(KEY_PLAYBACK_COMPLETION_DATE, media.getPlaybackCompletionDate().getTime());
values.put(KEY_PLAYED_DURATION, media.getPlayedDuration());
// Also reset stored playback speed for media
values.putNull(KEY_LAST_PLAYBACK_SPEED);
values.put(KEY_MEDIA_LAST_PLAYBACK_SPEED, LAST_PLAYBACK_SPEED_UNSET);
db.update(TABLE_NAME_FEED_MEDIA, values, KEY_ID + "=?",
new String[]{String.valueOf(media.getId())});
} else {