From cc43a876f5053ec7c4fa39f8805b2b4a6fdd19a4 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 31 Aug 2023 14:33:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=9F=B3=E9=87=8F=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E5=92=8C=E9=9D=99=E9=9F=B3=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 32 ++++++++++++++++++++++++++++---- mainwindow.h | 3 +++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 0027163..479c7f0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -301,9 +301,22 @@ void MainWindow::player_rewind_or_forward(int seconds) { char changeSongBuf[128] = ""; int len = sprintf(changeSongBuf, "seek %d\n", seconds); // 快进快退 seconds 秒 (seconds 为正->进,为负->退) - write(this->fifo_fd, changeSongBuf, len); // 将获取的下一首歌曲名写入到有名管道中 + write(this->fifo_fd, changeSongBuf, len); // 将快进快退指令写入到有名管道中 } +void MainWindow::volume_control(int value) +{ + char changeSongBuf[128] = ""; + int len = sprintf(changeSongBuf, "volume %d 1\n", value); // 音量调整到 value 大小 + write(this->fifo_fd, changeSongBuf, len); // 将音量控制指令写入到有名管道中 +} + +void MainWindow::volume_mute_switch(int mute_arg) +{ + char changeSongBuf[128] = ""; + int len = sprintf(changeSongBuf, "mute %d\n", mute_arg); // mute_arg 静音开关参数 (1->静音,0->取消静音) + write(this->fifo_fd, changeSongBuf, len); // 将静音控制指令写入到有名管道中 +} void MainWindow::on_last_btn_clicked() { @@ -317,15 +330,26 @@ void MainWindow::on_next_btn_clicked() void MainWindow::on_mute_btn_clicked() { - + if(mute_flag == 0) // 没静音则按下后设置静音 + { + ui->play_btn->setIcon(QIcon(":/icon/mute2")); +// volume_mute_switch(1); +// mute_flag = 1; + volume_mute_switch(++mute_flag); + } + else if (mute_flag == 1) // 已静音则按下后取消静音 + { + ui->play_btn->setIcon(QIcon(":/icon/mute1")); + volume_mute_switch(--mute_flag); + } } void MainWindow::on_volume_down_btn_clicked() { - + volume_control(-5); // 减 5 音量 } void MainWindow::on_volume_up_btn_clicked() { - + volume_control(5); // 加 5 音量 } diff --git a/mainwindow.h b/mainwindow.h index efebef3..0031112 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -33,6 +33,7 @@ public: vector vectorSong; // 歌曲名动态数组 int play_btn_flag = 0; // play 按钮点击标识 + int mute_flag = 0; // 静音状态标识 public: MainWindow(QWidget *parent = nullptr); @@ -48,6 +49,8 @@ public slots: void playNextSong(); // 切换歌曲槽函数I void playLastSong(); void player_rewind_or_forward(int seconds); // 快进快退函数 + void volume_control(int value); // 音量设置函数 + void volume_mute_switch(int mute_arg); // 静音切换函数 void setCurrentTimeLabel(int time); // 设置当前时间标签槽函数 void setCurrentSlider(int currentProgress); // 设置当前进度条