--- POSITION UPDATE --- Called by 'posTimer' whenever the 1 second interval expires. Updates the playback position of the current file if needed (not updated externally).
| 368 | // Called by 'posTimer' whenever the 1 second interval expires. |
| 369 | // Updates the playback position of the current file if needed (not updated externally). |
| 370 | void MainWindow::positionUpdate() { |
| 371 | //if (!playingTrack) { return; } |
| 372 | |
| 373 | // DEBUG |
| 374 | //std::cout << "Position Update..." << std::endl; |
| 375 | |
| 376 | // Obtain the info on the currently active remote. |
| 377 | // Obtain selected ID. |
| 378 | int index = ui->remotesComboBox->currentIndex(); |
| 379 | uint32_t id = ui->remotesComboBox->currentData().toUInt(); |
| 380 | |
| 381 | NCRemoteInstance* ris = 0; |
| 382 | if (index > separatorIndex) { |
| 383 | NCRemoteGroup& group = groups[id]; |
| 384 | if (group.remotes.size() < 1) { return; } |
| 385 | |
| 386 | ris = &(group.remotes[0]); |
| 387 | } |
| 388 | else if (index < separatorIndex) { |
| 389 | ris = &(remotes[index]); |
| 390 | } |
| 391 | |
| 392 | // DEBUG |
| 393 | //std::cout << "Position Update: Check pause..." << std::endl; |
| 394 | |
| 395 | // Check whether we're paused. |
| 396 | if (ris->status.status == NYMPH_PLAYBACK_STATUS_PAUSED) { |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | // DEBUG |
| 401 | //std::cout << "Position Update: Check time..." << std::endl; |
| 402 | |
| 403 | QTime now = QTime::currentTime(); |
| 404 | if (ris->timestamp.secsTo(now) < 1) { |
| 405 | // No need to update. |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | // Increase position by 1 second. |
| 410 | ris->position += 1; |
| 411 | |
| 412 | // Update timestamp. |
| 413 | ris->timestamp = now; |
| 414 | |
| 415 | // |
| 416 | //std::cout << "positionUpdate: position: " << ris->position << ", duration: " << ris->duration << std::endl; |
| 417 | |
| 418 | // Set position & duration in UI. |
| 419 | QTime position(0, 0); |
| 420 | position = position.addSecs((int64_t) ris->position); |
| 421 | QTime duration(0, 0); |
| 422 | duration = duration.addSecs(ris->status.duration); |
| 423 | ui->durationLabel->setText(position.toString("hh:mm:ss") + " / " + |
| 424 | duration.toString("hh:mm:ss")); |
| 425 | |
| 426 | ui->positionSlider->setValue((ris->position / ris->status.duration) * 1000); |
| 427 | } |