RTP player: Added pause button

Pause button added. Button is visible only when media are played.
This commit is contained in:
Jirka Novak 2020-12-29 14:41:14 +01:00
parent 936f2a9b70
commit 5a7f249edb
4 changed files with 35 additions and 0 deletions

View File

@ -648,6 +648,17 @@ void RtpAudioStream::startPlaying()
} }
} }
void RtpAudioStream::pausePlaying()
{
if (audio_output_) {
if (QAudio::ActiveState == audio_output_->state()) {
audio_output_->suspend();
} else if (QAudio::SuspendedState == audio_output_->state()) {
audio_output_->resume();
}
}
}
void RtpAudioStream::stopPlaying() void RtpAudioStream::stopPlaying()
{ {
if (audio_output_) { if (audio_output_) {

View File

@ -137,6 +137,7 @@ signals:
public slots: public slots:
void startPlaying(); void startPlaying();
void pausePlaying();
void stopPlaying(); void stopPlaying();
private: private:

View File

@ -153,6 +153,8 @@ RtpPlayerDialog::RtpPlayerDialog(QWidget &parent, CaptureFile &cf) :
ui->audioPlot->yAxis->setVisible(false); ui->audioPlot->yAxis->setVisible(false);
ui->playButton->setIcon(StockIcon("media-playback-start")); ui->playButton->setIcon(StockIcon("media-playback-start"));
ui->pauseButton->setIcon(StockIcon("media-playback-pause"));
ui->pauseButton->setCheckable(true);
ui->stopButton->setIcon(StockIcon("media-playback-stop")); ui->stopButton->setIcon(StockIcon("media-playback-stop"));
// Ordered, unique device names starting with the system default // Ordered, unique device names starting with the system default
@ -173,6 +175,7 @@ RtpPlayerDialog::RtpPlayerDialog(QWidget &parent, CaptureFile &cf) :
if (ui->outputDeviceComboBox->count() < 1) { if (ui->outputDeviceComboBox->count() < 1) {
ui->outputDeviceComboBox->setEnabled(false); ui->outputDeviceComboBox->setEnabled(false);
ui->playButton->setEnabled(false); ui->playButton->setEnabled(false);
ui->pauseButton->setEnabled(false);
ui->stopButton->setEnabled(false); ui->stopButton->setEnabled(false);
ui->outputDeviceComboBox->addItem(tr("No devices available")); ui->outputDeviceComboBox->addItem(tr("No devices available"));
} }
@ -458,6 +461,7 @@ void RtpPlayerDialog::addRtpStream(rtpstream_info_t *rtpstream)
} }
connect(ui->playButton, SIGNAL(clicked(bool)), audio_stream, SLOT(startPlaying())); connect(ui->playButton, SIGNAL(clicked(bool)), audio_stream, SLOT(startPlaying()));
connect(ui->pauseButton, SIGNAL(clicked(bool)), audio_stream, SLOT(pausePlaying()));
connect(ui->stopButton, SIGNAL(clicked(bool)), audio_stream, SLOT(stopPlaying())); connect(ui->stopButton, SIGNAL(clicked(bool)), audio_stream, SLOT(stopPlaying()));
connect(audio_stream, SIGNAL(startedPlaying()), this, SLOT(updateWidgets())); connect(audio_stream, SIGNAL(startedPlaying()), this, SLOT(updateWidgets()));
@ -545,6 +549,7 @@ void RtpPlayerDialog::keyPressEvent(QKeyEvent *event)
void RtpPlayerDialog::updateWidgets() void RtpPlayerDialog::updateWidgets()
{ {
bool enable_play = true; bool enable_play = true;
bool enable_pause = false;
bool enable_stop = false; bool enable_stop = false;
bool enable_timing = true; bool enable_timing = true;
@ -554,13 +559,22 @@ void RtpPlayerDialog::updateWidgets()
RtpAudioStream *audio_stream = ti->data(src_addr_col_, Qt::UserRole).value<RtpAudioStream*>(); RtpAudioStream *audio_stream = ti->data(src_addr_col_, Qt::UserRole).value<RtpAudioStream*>();
if (audio_stream->outputState() != QAudio::IdleState) { if (audio_stream->outputState() != QAudio::IdleState) {
enable_play = false; enable_play = false;
enable_pause = true;
enable_stop = true; enable_stop = true;
enable_timing = false; enable_timing = false;
} }
} }
ui->playButton->setEnabled(enable_play); ui->playButton->setEnabled(enable_play);
if (enable_play) {
ui->playButton->setVisible(true);
ui->pauseButton->setVisible(false);
} else if (enable_pause) {
ui->playButton->setVisible(false);
ui->pauseButton->setVisible(true);
}
ui->outputDeviceComboBox->setEnabled(enable_play); ui->outputDeviceComboBox->setEnabled(enable_play);
ui->pauseButton->setEnabled(enable_pause);
ui->stopButton->setEnabled(enable_stop); ui->stopButton->setEnabled(enable_stop);
cur_play_pos_->setVisible(enable_stop); cur_play_pos_->setVisible(enable_stop);
@ -717,6 +731,8 @@ void RtpPlayerDialog::on_playButton_clicked()
{ {
double start_time; double start_time;
ui->pauseButton->setChecked(false);
cur_play_pos_->point1->setCoords(start_marker_time_, 0.0); cur_play_pos_->point1->setCoords(start_marker_time_, 0.0);
cur_play_pos_->point2->setCoords(start_marker_time_, 1.0); cur_play_pos_->point2->setCoords(start_marker_time_, 1.0);
cur_play_pos_->setVisible(true); cur_play_pos_->setVisible(true);

View File

@ -131,6 +131,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QToolButton" name="pauseButton">
<property name="text">
<string/>
</property>
</widget>
</item>
<item> <item>
<spacer name="horizontalSpacer_4"> <spacer name="horizontalSpacer_4">
<property name="orientation"> <property name="orientation">