获取设置元数据函数 v1
This commit is contained in:
parent
95719184ec
commit
8a6275149e
@ -115,6 +115,8 @@ void MainWindow::mplayerInit()
|
||||
volume_control(currentVolume, 1); // 初始音量设置为 currentVolume->50
|
||||
setVolumeSlider(currentVolume); // 设置音量滑块初始位置
|
||||
|
||||
getAndSetMetaDatas(); // 获取第一首歌的元数据并设置到界面对应 label 中
|
||||
|
||||
// pthread_detach(t1);
|
||||
// pthread_detach(t2);
|
||||
|
||||
@ -174,6 +176,7 @@ void MainWindow::playNextSong()
|
||||
// write(this->fifo_fd, changeSongBuf.toUtf8().toStdString().c_str(),changeSongBuf.toUtf8().toStdString().size());
|
||||
ui->song_list_widget->setCurrentRow(index);
|
||||
write(this->fifo_fd, changeSongBuf, len); // 将获取的下一首歌曲名写入到有名管道中
|
||||
getAndSetMetaDatas();
|
||||
}
|
||||
|
||||
void MainWindow::playLastSong()
|
||||
@ -189,6 +192,7 @@ void MainWindow::playLastSong()
|
||||
// write(this->fifo_fd, changeSongBuf.toUtf8().toStdString().c_str(),changeSongBuf.toUtf8().toStdString().size());
|
||||
ui->song_list_widget->setCurrentRow(index);
|
||||
write(this->fifo_fd, changeSongBuf, len); // 将获取的下一首歌曲名写入到有名管道中
|
||||
getAndSetMetaDatas();
|
||||
}
|
||||
|
||||
void MainWindow::setCurrentTimeLabel(int time)
|
||||
@ -277,10 +281,11 @@ void *readPipeMSG(void *arg)
|
||||
// // 如果消息是 "当前歌曲元数据信息"
|
||||
// else if(strncmp(buf,"ANS_LENGTH", strlen("ANS_LENGTH")) == 0)
|
||||
// {
|
||||
// int currentProgress = 0;
|
||||
// sscanf(buf, "ANS_LENGTH=%d", ¤tProgress);
|
||||
// int metalength = 0;
|
||||
// sscanf(buf, "ANS_LENGTH=%d", &metalength);
|
||||
// // 给 UI 发送进度信号
|
||||
// emit p->currentProgressSignal(currentProgress);
|
||||
// emit p->currentProgressSignal(metalength);
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
@ -393,3 +398,65 @@ void MainWindow::on_volume_up_btn_clicked()
|
||||
setVolumeSlider(currentVolume); // 设置音量滑块位置
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::getMetaDatas()
|
||||
{
|
||||
// 发送获取的当前歌曲元数据信息的命令
|
||||
// 发送获取当前歌曲长度的命令 ANS_LENGTH
|
||||
write(fifo_fd, "get_time_length\n", strlen("get_time_length\n"));
|
||||
// 发送获取当前歌曲名的命令 ANS_META_TITLE
|
||||
write(fifo_fd, "get_file_name\n", strlen("get_file_name\n"));
|
||||
// 发送获取当前歌曲歌手的命令 ANS_META_ARTIST
|
||||
write(fifo_fd, "get_meta_artist\n", strlen("get_meta_artist\n"));
|
||||
// 发送获取当前歌曲专辑的命令 ANS_META_ALBU
|
||||
write(fifo_fd, "get_meta_album\n", strlen("get_meta_album\n"));
|
||||
}
|
||||
|
||||
void MainWindow::setMetaDatas()
|
||||
{
|
||||
// 发送获取当前歌曲名的命令 ANS_META_TITLE
|
||||
write(fifo_fd, "get_file_name\n", strlen("get_file_name\n"));
|
||||
// 发送获取当前歌曲歌手的命令 ANS_META_ARTIST
|
||||
write(fifo_fd, "get_meta_artist\n", strlen("get_meta_artist\n"));
|
||||
// 发送获取当前歌曲专辑的命令 ANS_META_ALBU
|
||||
write(fifo_fd, "get_meta_album\n", strlen("get_meta_album\n"));
|
||||
|
||||
char buf[256] = "";
|
||||
int ret = read(p->fd[0], buf, sizeof(buf)); // 从无名管道读取内容到 buf
|
||||
if(ret > 0)
|
||||
{
|
||||
// 判断消息的类型 :
|
||||
// 如果消息是 "当前歌曲的时长"
|
||||
if(strncmp(buf,"ANS_LENGTH",strlen("ANS_LENGTH")) == 0)
|
||||
{
|
||||
int song_length_time = 0;
|
||||
sscanf(buf,"ANS_LENGTH=%d",&song_length_time); // 从数据流 buf 中读取时间到 song_length_time
|
||||
// 给 UI 发送当前时间信号
|
||||
// emit p->currentTimeSignal(time);
|
||||
|
||||
int m = 0, s = 0;
|
||||
m = song_length_time / 60; // 算分钟
|
||||
s = song_length_time % 60; // 算秒钟
|
||||
|
||||
char buf[32] = "";
|
||||
sprintf(buf,"%02d:%02d",m,s);
|
||||
// 将歌曲当前时间设置到 label
|
||||
ui->time_right_label->setText(QString(buf));
|
||||
}
|
||||
// // 如果消息是 "当前歌曲播放进度"
|
||||
// else if(strncmp(buf,"ANS_META_TITLE", strlen("ANS_META_TITLE")) == 0)
|
||||
// {
|
||||
// int meta_title = 0;
|
||||
// sscanf(buf, "ANS_META_TITLE=%d", ¤tProgress);
|
||||
// // 给 UI 发送进度信号
|
||||
// emit p->currentProgressSignal(currentProgress);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::getAndSetMetaDatas()
|
||||
{
|
||||
getMetaDatas();
|
||||
usleep(100*1000);
|
||||
setMetaDatas();
|
||||
}
|
||||
|
@ -54,11 +54,15 @@ public slots:
|
||||
void setCurrentTimeLabel(int time); // 设置当前时间标签槽函数
|
||||
void setCurrentSlider(int currentProgress); // 设置当前进度条
|
||||
void setVolumeSlider(int currentVolume); // 设置当前音量条
|
||||
void getMetaDatas(); // 获取元数据
|
||||
void setMetaDatas(); // 设置元数据
|
||||
void getAndSetMetaDatas(); // 获取并设置
|
||||
|
||||
signals:
|
||||
void currentTimeSignal(int time); // 当前时间信号
|
||||
void currentProgressSignal(int currentProgress); // 当前进度信号
|
||||
void currentVolumeSignal(int currentVolume); // 当前音量信号
|
||||
void metaLengthSignal(); // 歌曲长度元数据
|
||||
|
||||
private slots:
|
||||
void on_play_btn_clicked();
|
||||
|
Loading…
x
Reference in New Issue
Block a user