diff --git a/src/Player.cpp b/src/Player.cpp index 98ec00a..ba985b7 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -52,6 +52,17 @@ void Player::pauseActive() pause(); } +bool Player::skipToStartActive(const bool with_pause) +{ + if (with_pause) { pause(); } + if (m_active) + { + setPosition(0); + return true; + } + return false; +} + void Player::mediaPlayerStatusChanged(MediaStatus status) { if (!m_ready && status == QMediaPlayer::MediaStatus::LoadedMedia) diff --git a/src/Player.h b/src/Player.h index ca8bca5..462f266 100644 --- a/src/Player.h +++ b/src/Player.h @@ -19,6 +19,7 @@ class Player : public QMediaPlayer void setNextPlayer(Player* mediaPlayer); bool playActive(bool force = false); void pauseActive(); + bool skipToStartActive(bool with_pause = false); signals: void playerLoaded(); diff --git a/src/Track.cpp b/src/Track.cpp index 062e54f..ee1df9e 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -123,6 +123,12 @@ void Track::pause() m_player_B->pauseActive(); } +void Track::skipToStart() +{ + const auto a = m_player_A->skipToStartActive(); + m_player_B->skipToStartActive(a); +} + qint64 Track::duration() const { return m_track_duration; diff --git a/src/Track.h b/src/Track.h index 461a654..2336755 100644 --- a/src/Track.h +++ b/src/Track.h @@ -32,6 +32,7 @@ class Track : public QObject bool isPlaying() const; void play(); void pause(); + void skipToStart(); qint64 duration() const; diff --git a/src/TrackControls.cpp b/src/TrackControls.cpp index a8c5f2a..9870cf0 100644 --- a/src/TrackControls.cpp +++ b/src/TrackControls.cpp @@ -113,6 +113,11 @@ void TrackControls::statusChanged(int state) } } +void TrackControls::skipToStart() +{ + m_track->skipToStart(); +} + void TrackControls::trackLoaded() { if (m_track->errors().empty()) @@ -170,6 +175,9 @@ bool TrackControls::eventFilter(QObject* watched, QEvent* event) void TrackControls::addItemsToMenu(QMenu* menu) const { + auto* skip_to_start = menu->addAction(tr("Skip to start")); + connect(skip_to_start, &QAction::triggered, this, &TrackControls::skipToStart); + auto* show_settings = menu->addAction(tr("Edit Settings")); connect(show_settings, &QAction::triggered, this, [this]() { m_settings->show(); }); diff --git a/src/TrackControls.h b/src/TrackControls.h index cb0c205..edcaee4 100644 --- a/src/TrackControls.h +++ b/src/TrackControls.h @@ -33,6 +33,7 @@ public slots: void volumeChanged(int value); void transitionChanged(int state); void statusChanged(int state); + void skipToStart(); void trackLoaded(); void playerError(); diff --git a/src/translations/soundscape_de.ts b/src/translations/soundscape_de.ts index af3b5fb..29543db 100644 --- a/src/translations/soundscape_de.ts +++ b/src/translations/soundscape_de.ts @@ -167,22 +167,27 @@ für Anwendungsmenü TrackControls - + + Skip to start + An den Anfang springen + + + Edit Settings Spur-Einstellungen - + Move Up Spur hoch schieben - + Move Down Spur runter schieben - + Remove Spur entfernen diff --git a/src/translations/soundscape_it.ts b/src/translations/soundscape_it.ts index 17f9409..e535c1d 100644 --- a/src/translations/soundscape_it.ts +++ b/src/translations/soundscape_it.ts @@ -166,22 +166,27 @@ to access application menu TrackControls - + + Skip to start + + + + Edit Settings Modifica impostazioni - + Move Up Sposta in alto - + Move Down Sposta in basso - + Remove Rimuovi diff --git a/src/translations/soundscape_ru.ts b/src/translations/soundscape_ru.ts index 182b1eb..cfa6097 100644 --- a/src/translations/soundscape_ru.ts +++ b/src/translations/soundscape_ru.ts @@ -167,22 +167,27 @@ to access application menu TrackControls - + + Skip to start + Перейти на начало трека + + + Edit Settings Параметры - + Move Up Переместить вверх - + Move Down Переместить вниз - + Remove Удалить diff --git a/tests/TestPlayer.cpp b/tests/TestPlayer.cpp index f794e74..d980ff5 100644 --- a/tests/TestPlayer.cpp +++ b/tests/TestPlayer.cpp @@ -32,6 +32,7 @@ private slots: void testNextPlayerOutGapIn(); void testNextPlayerCrossFade(); void testPlayPauseActive(); + void testSkipToStartActive(); private: const QTemporaryDir tmp_dir; @@ -255,5 +256,25 @@ void TestPlayer::testPlayPauseActive() QVERIFY(player->playbackState() == QMediaPlayer::PlaybackState::PlayingState); } +void TestPlayer::testSkipToStartActive() +{ + Track track; + auto* player = track.playerA(); + QSignalSpy player_loaded(player, &Player::playerLoaded); + player->setSource(QUrl::fromLocalFile(file_name_audio_ok)); + QVERIFY(player_loaded.wait()); + player->m_active = false; + player->stop(); + + QVERIFY(!player->playActive()); + QVERIFY(!player->skipToStartActive()); + + QVERIFY(player->playActive(true)); + QVERIFY(player->playbackState() == QMediaPlayer::PlaybackState::PlayingState); + QVERIFY(player->skipToStartActive(true)); + QVERIFY(player->playbackState() != QMediaPlayer::PlaybackState::PlayingState); + QVERIFY(player->position() == 0); +} + QTEST_MAIN(TestPlayer) #include "TestPlayer.moc" diff --git a/tests/TestTrackControls.cpp b/tests/TestTrackControls.cpp index 2354a10..d025e9f 100644 --- a/tests/TestTrackControls.cpp +++ b/tests/TestTrackControls.cpp @@ -132,10 +132,11 @@ void TestTrackControls::testMenu() TrackControls track_controls(QJsonObject(), QDir(), &main_window); auto menu = track_controls.m_mouse_menu; auto actions = menu->actions(); - QCOMPARE(actions.at(0)->text(), "Edit Settings"); - QCOMPARE(actions.at(1)->text(), "Move Up"); - QCOMPARE(actions.at(2)->text(), "Move Down"); - QCOMPARE(actions.at(3)->text(), "Remove"); + QCOMPARE(actions.at(0)->text(), "Skip to start"); + QCOMPARE(actions.at(1)->text(), "Edit Settings"); + QCOMPARE(actions.at(2)->text(), "Move Up"); + QCOMPARE(actions.at(3)->text(), "Move Down"); + QCOMPARE(actions.at(4)->text(), "Remove"); } void TestTrackControls::testPauseAndResume()