mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 11:46:55 +01:00
Set fast forward and rewind time
This commit is contained in:
parent
76b6ae654b
commit
fd30ec8189
@ -12,6 +12,8 @@ import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
@ -46,7 +48,9 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
protected SeekBar sbPosition;
|
||||
protected ImageButton butPlay;
|
||||
protected ImageButton butRev;
|
||||
protected TextView txtvRev;
|
||||
protected ImageButton butFF;
|
||||
protected TextView txtvFF;
|
||||
|
||||
private PlaybackController newPlaybackController() {
|
||||
return new PlaybackController(this, false) {
|
||||
@ -222,7 +226,6 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d(TAG, "onStop()");
|
||||
|
||||
if (controller != null) {
|
||||
controller.release();
|
||||
}
|
||||
@ -373,6 +376,8 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
if (controller != null) {
|
||||
int currentPosition = controller.getPosition();
|
||||
int duration = controller.getDuration();
|
||||
Log.d(TAG, "currentPosition " + Converter
|
||||
.getDurationStringLong(currentPosition));
|
||||
if (currentPosition != PlaybackService.INVALID_TIME
|
||||
&& duration != PlaybackService.INVALID_TIME
|
||||
&& controller.getMedia() != null) {
|
||||
@ -381,8 +386,7 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
txtvLength.setText(Converter.getDurationStringLong(duration));
|
||||
updateProgressbarPosition(currentPosition, duration);
|
||||
} else {
|
||||
Log.w(TAG,
|
||||
"Could not react to position observer update because of invalid time");
|
||||
Log.w(TAG, "Could not react to position observer update because of invalid time");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -426,7 +430,11 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
txtvLength = (TextView) findViewById(R.id.txtvLength);
|
||||
butPlay = (ImageButton) findViewById(R.id.butPlay);
|
||||
butRev = (ImageButton) findViewById(R.id.butRev);
|
||||
txtvRev = (TextView) findViewById(R.id.txtvRev);
|
||||
txtvRev.setText(String.valueOf(UserPreferences.getRewindSecs()));
|
||||
butFF = (ImageButton) findViewById(R.id.butFF);
|
||||
txtvFF = (TextView) findViewById(R.id.txtvFF);
|
||||
txtvFF.setText(String.valueOf(UserPreferences.getFastFowardSecs()));
|
||||
|
||||
// SEEKBAR SETUP
|
||||
|
||||
@ -437,10 +445,100 @@ public abstract class MediaplayerActivity extends ActionBarActivity
|
||||
butPlay.setOnClickListener(controller.newOnPlayButtonClickListener());
|
||||
|
||||
if (butFF != null) {
|
||||
butFF.setOnClickListener(controller.newOnFFButtonClickListener());
|
||||
butFF.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int curr = controller.getPosition();
|
||||
controller.seekTo(curr + UserPreferences.getFastFowardSecs() * 1000);
|
||||
}
|
||||
});
|
||||
butFF.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
||||
int choice;
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
int checked = 0;
|
||||
int rewindSecs = UserPreferences.getFastFowardSecs();
|
||||
final int[] values = getResources().getIntArray(R.array.seek_delta_values);
|
||||
final String[] choices = new String[values.length];
|
||||
for(int i=0; i < values.length; i++) {
|
||||
if (rewindSecs == values[i]) {
|
||||
checked = i;
|
||||
}
|
||||
choices[i] = String.valueOf(values[i]) + " "
|
||||
+ getString(R.string.time_unit_seconds);
|
||||
}
|
||||
choice = values[checked];
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MediaplayerActivity.this);
|
||||
builder.setTitle(R.string.pref_fast_forward);
|
||||
builder.setSingleChoiceItems(choices, checked,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
choice = values[which];
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel_label, null);
|
||||
builder.setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UserPreferences.setPrefFastForwardSecs(choice);
|
||||
txtvFF.setText(String.valueOf(choice));
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (butRev != null) {
|
||||
butRev.setOnClickListener(controller.newOnRevButtonClickListener());
|
||||
butRev.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int curr = controller.getPosition();
|
||||
controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000);
|
||||
}
|
||||
});
|
||||
butRev.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
|
||||
int choice;
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
int checked = 0;
|
||||
int rewindSecs = UserPreferences.getRewindSecs();
|
||||
final int[] values = getResources().getIntArray(R.array.seek_delta_values);
|
||||
final String[] choices = new String[values.length];
|
||||
for(int i=0; i < values.length; i++) {
|
||||
if (rewindSecs == values[i]) {
|
||||
checked = i;
|
||||
}
|
||||
choices[i] = String.valueOf(values[i]) + " "
|
||||
+ getString(R.string.time_unit_seconds);
|
||||
}
|
||||
choice = values[checked];
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(MediaplayerActivity.this);
|
||||
builder.setTitle(R.string.pref_rewind);
|
||||
builder.setSingleChoiceItems(choices, checked,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
choice = values[which];
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel_label, null);
|
||||
builder.setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
UserPreferences.setPrefRewindSecs(choice);
|
||||
txtvRev.setText(String.valueOf(choice));
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -95,6 +95,18 @@
|
||||
tools:src="@drawable/ic_fast_rewind_white_36dp"
|
||||
tools:background="@android:color/holo_blue_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvRev"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="32dp"
|
||||
android:layout_alignTop="@id/butRev"
|
||||
android:layout_alignLeft="@id/butRev"
|
||||
android:layout_alignRight="@id/butRev"
|
||||
android:gravity="center"
|
||||
android:text="30"
|
||||
android:textSize="8dp"
|
||||
android:clickable="false"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/butFF"
|
||||
android:layout_width="@dimen/audioplayer_playercontrols_length"
|
||||
@ -106,6 +118,18 @@
|
||||
tools:src="@drawable/ic_fast_forward_white_36dp"
|
||||
tools:background="@android:color/holo_blue_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvFF"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="32dp"
|
||||
android:layout_alignTop="@id/butFF"
|
||||
android:layout_alignLeft="@id/butFF"
|
||||
android:layout_alignRight="@id/butFF"
|
||||
android:gravity="center"
|
||||
android:text="30"
|
||||
android:textSize="8dp"
|
||||
android:clickable="false"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/butPlaybackSpeed"
|
||||
android:layout_width="@dimen/audioplayer_playercontrols_length"
|
||||
|
@ -78,14 +78,6 @@
|
||||
android:summary="@string/pref_pausePlaybackForFocusLoss_sum"
|
||||
android:title="@string/pref_pausePlaybackForFocusLoss_title" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="30"
|
||||
android:entries="@array/seek_delta_values"
|
||||
android:entryValues="@array/seek_delta_values"
|
||||
android:key="prefSeekDeltaSecs"
|
||||
android:summary="@string/pref_seek_delta_sum"
|
||||
android:title="@string/pref_seek_delta_title" />
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/network_pref">
|
||||
<ListPreference
|
||||
|
@ -344,11 +344,11 @@ public class PlaybackService extends Service {
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
|
||||
mediaPlayer.seekDelta(UserPreferences.getSeekDeltaMs());
|
||||
mediaPlayer.seekDelta(UserPreferences.getFastFowardSecs() * 1000);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
|
||||
case KeyEvent.KEYCODE_MEDIA_REWIND:
|
||||
mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs());
|
||||
mediaPlayer.seekDelta(-UserPreferences.getRewindSecs() * 1000);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_STOP:
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
@ -481,9 +481,8 @@ public class PlaybackService extends Service {
|
||||
}
|
||||
|
||||
Intent statusUpdate = new Intent(ACTION_PLAYER_STATUS_CHANGED);
|
||||
statusUpdate.putExtra(EXTRA_NEW_PLAYER_STATUS, newInfo.playerStatus.ordinal());
|
||||
// statusUpdate.putExtra(EXTRA_NEW_PLAYER_STATUS, newInfo.playerStatus.ordinal());
|
||||
sendBroadcast(statusUpdate);
|
||||
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
|
||||
updateWidget();
|
||||
refreshRemoteControlClientState(newInfo);
|
||||
bluetoothNotifyChange(newInfo, AVRCP_ACTION_PLAYER_STATUS_CHANGED);
|
||||
@ -626,7 +625,6 @@ public class PlaybackService extends Service {
|
||||
prepareImmediately = startWhenPrepared = true;
|
||||
} else {
|
||||
Log.d(TAG, "No more episodes available to play");
|
||||
|
||||
prepareImmediately = startWhenPrepared = false;
|
||||
stopForeground(true);
|
||||
stopWidgetUpdater();
|
||||
@ -933,7 +931,6 @@ public class PlaybackService extends Service {
|
||||
// Auto flattr
|
||||
if (isAutoFlattrable(media) &&
|
||||
(media.getPlayedDuration() > UserPreferences.getAutoFlattrPlayedDurationThreshold() * duration)) {
|
||||
|
||||
Log.d(TAG, "saveCurrentPosition: performing auto flattr since played duration " + Integer.toString(media.getPlayedDuration())
|
||||
+ " is " + UserPreferences.getAutoFlattrPlayedDurationThreshold() * 100 + "% of file duration " + Integer.toString(duration));
|
||||
DBTasks.flattrItemIfLoggedIn(this, item);
|
||||
|
@ -449,15 +449,15 @@ public class PlaybackServiceMediaPlayer {
|
||||
if (playerStatus == PlayerStatus.PLAYING
|
||||
|| playerStatus == PlayerStatus.PAUSED
|
||||
|| playerStatus == PlayerStatus.PREPARED) {
|
||||
if (stream) {
|
||||
// statusBeforeSeeking = playerStatus;
|
||||
// setPlayerStatus(PlayerStatus.SEEKING, media);
|
||||
if (!stream) {
|
||||
statusBeforeSeeking = playerStatus;
|
||||
setPlayerStatus(PlayerStatus.SEEKING, media);
|
||||
}
|
||||
mediaPlayer.seekTo(t);
|
||||
|
||||
} else if (playerStatus == PlayerStatus.INITIALIZED) {
|
||||
media.setPosition(t);
|
||||
startWhenPrepared.set(true);
|
||||
startWhenPrepared.set(false);
|
||||
prepare();
|
||||
}
|
||||
playerLock.unlock();
|
||||
@ -534,20 +534,20 @@ public class PlaybackServiceMediaPlayer {
|
||||
* Returns the position of the current media object or INVALID_TIME if the position could not be retrieved.
|
||||
*/
|
||||
public int getPosition() {
|
||||
if (!playerLock.tryLock()) {
|
||||
return INVALID_TIME;
|
||||
}
|
||||
playerLock.lock();
|
||||
|
||||
int retVal = INVALID_TIME;
|
||||
if (playerStatus == PlayerStatus.PLAYING
|
||||
|| playerStatus == PlayerStatus.PAUSED
|
||||
|| playerStatus == PlayerStatus.PREPARED) {
|
||||
|| playerStatus == PlayerStatus.PREPARED
|
||||
|| playerStatus == PlayerStatus.SEEKING) {
|
||||
retVal = mediaPlayer.getCurrentPosition();
|
||||
} else if (media != null && media.getPosition() > 0) {
|
||||
retVal = media.getPosition();
|
||||
}
|
||||
|
||||
playerLock.unlock();
|
||||
Log.d(TAG, "getPosition() -> " + retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@ -735,6 +735,7 @@ public class PlaybackServiceMediaPlayer {
|
||||
|
||||
int state;
|
||||
if (playerStatus != null) {
|
||||
Log.d(TAG, "playerStatus: " + playerStatus.toString());
|
||||
switch (playerStatus) {
|
||||
case PLAYING:
|
||||
state = PlaybackStateCompat.STATE_PLAYING;
|
||||
@ -1095,13 +1096,13 @@ public class PlaybackServiceMediaPlayer {
|
||||
@Override
|
||||
public void onFastForward() {
|
||||
super.onFastForward();
|
||||
seekDelta(UserPreferences.getSeekDeltaMs());
|
||||
seekDelta(UserPreferences.getFastFowardSecs() * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRewind() {
|
||||
super.onRewind();
|
||||
seekDelta(-UserPreferences.getSeekDeltaMs());
|
||||
seekDelta(-UserPreferences.getRewindSecs() * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,13 +32,11 @@ import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.danoeh.antennapod.core.BuildConfig;
|
||||
import de.danoeh.antennapod.core.R;
|
||||
import de.danoeh.antennapod.core.feed.Chapter;
|
||||
import de.danoeh.antennapod.core.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
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.service.playback.PlaybackServiceMediaPlayer;
|
||||
import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
||||
@ -174,8 +172,7 @@ public abstract class PlaybackController {
|
||||
* as the arguments of the launch intent.
|
||||
*/
|
||||
private void bindToService() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Trying to connect to service");
|
||||
Log.d(TAG, "Trying to connect to service");
|
||||
AsyncTask<Void, Void, Intent> intentLoader = new AsyncTask<Void, Void, Intent>() {
|
||||
@Override
|
||||
protected Intent doInBackground(Void... voids) {
|
||||
@ -211,8 +208,7 @@ public abstract class PlaybackController {
|
||||
* played media or null if no last played media could be found.
|
||||
*/
|
||||
private Intent getPlayLastPlayedMediaIntent() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Trying to restore last played media");
|
||||
Log.d(TAG, "Trying to restore last played media");
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(activity.getApplicationContext());
|
||||
long currentlyPlayingMedia = PlaybackPreferences
|
||||
@ -240,8 +236,7 @@ public abstract class PlaybackController {
|
||||
return serviceIntent;
|
||||
}
|
||||
}
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "No last played media found");
|
||||
Log.d(TAG, "No last played media found");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -253,8 +248,7 @@ public abstract class PlaybackController {
|
||||
|| (positionObserverFuture != null && positionObserverFuture
|
||||
.isDone()) || positionObserverFuture == null) {
|
||||
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Setting up position observer");
|
||||
Log.d(TAG, "Setting up position observer");
|
||||
positionObserver = new MediaPositionObserver();
|
||||
positionObserverFuture = schedExecutor.scheduleWithFixedDelay(
|
||||
positionObserver, MediaPositionObserver.WAITING_INTERVALL,
|
||||
@ -266,8 +260,7 @@ public abstract class PlaybackController {
|
||||
private void cancelPositionObserver() {
|
||||
if (positionObserverFuture != null) {
|
||||
boolean result = positionObserverFuture.cancel(true);
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "PositionObserver cancelled. Result: " + result);
|
||||
Log.d(TAG, "PositionObserver cancelled. Result: " + result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,8 +288,7 @@ public abstract class PlaybackController {
|
||||
protected BroadcastReceiver statusUpdate = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Received statusUpdate Intent.");
|
||||
Log.d(TAG, "Received statusUpdate Intent.");
|
||||
if (isConnectedToPlaybackService()) {
|
||||
PlaybackServiceMediaPlayer.PSMPInfo info = playbackService.getPSMPInfo();
|
||||
status = info.playerStatus;
|
||||
@ -353,8 +345,7 @@ public abstract class PlaybackController {
|
||||
}
|
||||
|
||||
} else {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Bad arguments. Won't handle intent");
|
||||
Log.d(TAG, "Bad arguments. Won't handle intent");
|
||||
}
|
||||
} else {
|
||||
bindToService();
|
||||
@ -425,6 +416,7 @@ public abstract class PlaybackController {
|
||||
pauseResource = R.drawable.ic_av_pause_circle_outline_80dp;
|
||||
}
|
||||
|
||||
Log.d(TAG, "status: " + status.toString());
|
||||
switch (status) {
|
||||
|
||||
case ERROR:
|
||||
@ -470,6 +462,7 @@ public abstract class PlaybackController {
|
||||
updatePlayButtonAppearance(playResource, playText);
|
||||
break;
|
||||
case SEEKING:
|
||||
onPositionObserverUpdate();
|
||||
postStatusMsg(R.string.player_seeking_msg);
|
||||
break;
|
||||
case INITIALIZED:
|
||||
@ -505,8 +498,7 @@ public abstract class PlaybackController {
|
||||
* information has to be refreshed
|
||||
*/
|
||||
void queryService() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Querying service info");
|
||||
Log.d(TAG, "Querying service info");
|
||||
if (playbackService != null) {
|
||||
status = playbackService.getStatus();
|
||||
media = playbackService.getPlayable();
|
||||
@ -614,28 +606,6 @@ public abstract class PlaybackController {
|
||||
};
|
||||
}
|
||||
|
||||
public OnClickListener newOnRevButtonClickListener() {
|
||||
return new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
playbackService.seekDelta(-UserPreferences.getSeekDeltaMs());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public OnClickListener newOnFFButtonClickListener() {
|
||||
return new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (status == PlayerStatus.PLAYING) {
|
||||
playbackService.seekDelta(UserPreferences.getSeekDeltaMs());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean serviceAvailable() {
|
||||
return playbackService != null;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
</string-array>
|
||||
|
||||
|
||||
<string-array name="seek_delta_values">
|
||||
<integer-array name="seek_delta_values">
|
||||
<item>5</item>
|
||||
<item>10</item>
|
||||
<item>15</item>
|
||||
@ -18,7 +18,7 @@
|
||||
<item>30</item>
|
||||
<item>45</item>
|
||||
<item>60</item>
|
||||
</string-array>
|
||||
</integer-array>
|
||||
|
||||
<string-array name="update_intervall_options">
|
||||
<item>Manual</item>
|
||||
|
@ -268,8 +268,8 @@
|
||||
<string name="pref_gpodnet_setlogin_information_sum">Change the login information for your gpodder.net account.</string>
|
||||
<string name="pref_playback_speed_title">Playback Speeds</string>
|
||||
<string name="pref_playback_speed_sum">Customize the speeds available for variable speed audio playback</string>
|
||||
<string name="pref_seek_delta_title">Seek time</string>
|
||||
<string name="pref_seek_delta_sum">Seek this many seconds when rewinding or fast-forwarding</string>
|
||||
<string name="pref_fast_forward">Fast forward time</string>
|
||||
<string name="pref_rewind">Rewind time</string>
|
||||
<string name="pref_gpodnet_sethostname_title">Set hostname</string>
|
||||
<string name="pref_gpodnet_sethostname_use_default_host">Use default host</string>
|
||||
<string name="pref_expandNotify_title">Expand Notification</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user