Merge pull request #41 from chme/skipprev

rfc: Change behavior of skip to previous song
This commit is contained in:
ejurgensen 2014-09-12 21:45:15 +02:00
commit f543b768ac
2 changed files with 30 additions and 6 deletions

View File

@ -362,7 +362,7 @@ laudio_start(uint64_t cur_pos, uint64_t next_pkt)
pcm_start_pos = next_pkt + pcm_buf_threshold; pcm_start_pos = next_pkt + pcm_buf_threshold;
/* Compensate threshold, as it's taken into account by snd_pcm_delay() */ /* Compensate threshold, as it's taken into account by snd_pcm_delay() */
pcm_pos += pcm_buf_threshold; //pcm_pos += pcm_buf_threshold;
DPRINTF(E_DBG, L_LAUDIO, "PCM pos %" PRIu64 ", start pos %" PRIu64 "\n", pcm_pos, pcm_start_pos); DPRINTF(E_DBG, L_LAUDIO, "PCM pos %" PRIu64 ", start pos %" PRIu64 "\n", pcm_pos, pcm_start_pos);

View File

@ -2684,6 +2684,7 @@ static int
playback_prev_bh(struct player_command *cmd) playback_prev_bh(struct player_command *cmd)
{ {
int ret; int ret;
int pos_sec;
if (!cur_streaming) if (!cur_streaming)
{ {
@ -2697,12 +2698,34 @@ playback_prev_bh(struct player_command *cmd)
source_stop(cur_streaming); source_stop(cur_streaming);
ret = source_prev(); /* Compute the playing time in seconds for the current song. */
if (ret < 0) if (cur_streaming->end > cur_streaming->stream_start)
{ pos_sec = (cur_streaming->end - cur_streaming->stream_start) / 44100;
playback_abort(); else
pos_sec = 0;
return -1; /* Only skip to the previous song if the playing time is less than 3 seconds,
otherwise restart the current song. */
DPRINTF(E_DBG, L_PLAYER, "Skipping song played %d sec\n", pos_sec);
if (pos_sec < 3)
{
ret = source_prev();
if (ret < 0)
{
playback_abort();
return -1;
}
}
else
{
ret = source_open(cur_streaming, 1);
if (ret < 0)
{
playback_abort();
return -1;
}
} }
if (player_state == PLAY_STOPPED) if (player_state == PLAY_STOPPED)
@ -2719,6 +2742,7 @@ playback_prev_bh(struct player_command *cmd)
return 0; return 0;
} }
static int static int
playback_next_bh(struct player_command *cmd) playback_next_bh(struct player_command *cmd)
{ {