From 32c85bbe1f279b91eeb88074fafbe3564f1fe849 Mon Sep 17 00:00:00 2001 From: flykhan Date: Thu, 31 Aug 2023 12:33:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=9B=B2=E7=9B=AE=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E8=B0=83=E8=AF=95=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 16 +++++++++++++++- mainwindow.h | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 4b1097c..768d2e2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -155,6 +155,20 @@ void MainWindow::playNextSong() write(this->fifo_fd, changeSongBuf, len); // 将获取的下一首歌曲名写入到有名管道中 } +void MainWindow::playLastSong() +{ + index--; + if(index == -1) + index = vectorSong.size() - 1; // 当索引到达歌曲 0 时,将索引置为最后一个歌曲,循环索引 + char changeSongBuf[128] = ""; + // 将 loadfile 'song_name_path' 写入字符数组 + int len = sprintf(changeSongBuf, "loadfile /home/flykhan/qtmplayer/song/%s\n", vectorSong[index].c_str()); + // int len = sprintf(changeSongBuf, "loadfile ./song/%s\n", vectorSong[index].c_str()); + qDebug() << changeSongBuf << endl; // 控制台打印下一首歌的名字 + // write(this->fifo_fd, changeSongBuf.toUtf8().toStdString().c_str(),changeSongBuf.toUtf8().toStdString().size()); + write(this->fifo_fd, changeSongBuf, len); // 将获取的下一首歌曲名写入到有名管道中 +} + void MainWindow::setCurrentTimeLabel(int time) { int m = 0, s = 0; @@ -272,7 +286,7 @@ void MainWindow::on_play_btn_clicked() void MainWindow::on_back_btn_clicked() { - + playLastSong(); } void MainWindow::on_front_btn_clicked() diff --git a/mainwindow.h b/mainwindow.h index 122fb19..22f976b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -46,6 +46,7 @@ public: public slots: void playNextSong(); // 切换歌曲槽函数I + void playLastSong(); void setCurrentTimeLabel(int time); // 设置当前时间标签槽函数 void setCurrentSlider(int currentProgress); // 设置当前进度条