If we don't know the length of a song from the metadata, get it from the pipeline which has the real length. Fixes #2818 when the length isn't in the podcast metadata.

This commit is contained in:
David Sansome 2014-05-29 21:33:53 +10:00
parent d99f4032b3
commit 162b2efbb0
2 changed files with 12 additions and 5 deletions

View File

@ -192,15 +192,21 @@ void GstEngine::ReloadSettings() {
qint64 GstEngine::position_nanosec() const {
if (!current_pipeline_) return 0;
qint64 result = current_pipeline_->position() - beginning_nanosec_;
const qint64 result = current_pipeline_->position() - beginning_nanosec_;
return qint64(qMax(0ll, result));
}
qint64 GstEngine::length_nanosec() const {
if (!current_pipeline_) return 0;
qint64 result = end_nanosec_ - beginning_nanosec_;
return qint64(qMax(0ll, result));
const qint64 result = end_nanosec_ - beginning_nanosec_;
if (result > 0) {
return result;
} else {
// Get the length from the pipeline if we don't know.
return current_pipeline_->length();
}
}
Engine::State GstEngine::state() const {

View File

@ -1280,7 +1280,7 @@ void MainWindow::UpdateTrackPosition() {
PlaylistItemPtr item(app_->player()->GetCurrentItem());
const int position = std::floor(
float(app_->player()->engine()->position_nanosec()) / kNsecPerSec + 0.5);
const int length = item->Metadata().length_nanosec() / kNsecPerSec;
const int length = app_->player()->engine()->length_nanosec() / kNsecPerSec;
const int scrobble_point = playlist->scrobble_point_nanosec() / kNsecPerSec;
if (length <= 0) {
@ -1339,7 +1339,8 @@ void MainWindow::UpdateTrackSliderPosition() {
const int slider_position = std::floor(
float(app_->player()->engine()->position_nanosec()) / kNsecPerMsec);
const int slider_length = item->Metadata().length_nanosec() / kNsecPerMsec;
const int slider_length =
app_->player()->engine()->length_nanosec() / kNsecPerMsec;
// Update the slider
ui_->track_slider->SetValue(slider_position, slider_length);