diff --git a/src/file.hpp b/src/file.hpp index 20c4ca57..ab7e9840 100644 --- a/src/file.hpp +++ b/src/file.hpp @@ -26,6 +26,7 @@ struct GrooveFilePrivate { pthread_mutex_t seek_mutex; int64_t seek_pos; // -1 if no seek request int seek_flush; // whether the seek request wants us to flush the buffer + bool ever_seeked; int eof; double audio_clock; // position of the decode head diff --git a/src/player.cpp b/src/player.cpp index 45e144c1..402f16cb 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -301,11 +301,9 @@ static void audio_callback(struct SoundIoOutStream *outstream, int ret = groove_sink_buffer_get(sink, &p->audio_buf, 0); if (ret == GROOVE_BUFFER_END) { + emit_event(p->eventq, GROOVE_EVENT_NOWPLAYING); p->play_head = NULL; p->play_pos = -1.0; - // emit the event after setting play head so user can check - // the play head - emit_event(p->eventq, GROOVE_EVENT_NOWPLAYING); } else if (ret == GROOVE_BUFFER_YES) { if (p->play_head != p->audio_buf->item) emit_event(p->eventq, GROOVE_EVENT_NOWPLAYING); diff --git a/src/playlist.cpp b/src/playlist.cpp index 2da4e863..ce0778dc 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -560,15 +560,18 @@ static int decode_one_frame(struct GroovePlaylist *playlist, struct GrooveFile * // handle seek requests pthread_mutex_lock(&f->seek_mutex); if (f->seek_pos >= 0) { - int64_t seek_pos = f->seek_pos; - if (seek_pos == 0 && f->audio_st->start_time != AV_NOPTS_VALUE) - seek_pos = f->audio_st->start_time; - if (av_seek_frame(f->ic, f->audio_stream_index, seek_pos, 0) < 0) { - av_log(NULL, AV_LOG_ERROR, "%s: error while seeking\n", f->ic->filename); - } else if (f->seek_flush) { - every_sink_flush(playlist); + if (f->seek_pos != 0 || f->seek_flush || f->ever_seeked) { + int64_t seek_pos = f->seek_pos; + if (seek_pos == 0 && f->audio_st->start_time != AV_NOPTS_VALUE) + seek_pos = f->audio_st->start_time; + if (av_seek_frame(f->ic, f->audio_stream_index, seek_pos, 0) < 0) { + av_log(NULL, AV_LOG_ERROR, "%s: error while seeking\n", f->ic->filename); + } else if (f->seek_flush) { + every_sink_flush(playlist); + } + avcodec_flush_buffers(f->audio_st->codec); } - avcodec_flush_buffers(f->audio_st->codec); + f->ever_seeked = true; f->seek_pos = -1; f->eof = 0; }