2023-08-29 17:08:51 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
2023-08-30 20:59:44 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
|
|
|
|
void *getTimerThreadFunc(void *arg); // 发送获取当前时间的 mplayer 命令
|
|
|
|
void *readPipeMSG(void *arg); // 获取当前时间的线程
|
|
|
|
|
2023-08-29 17:08:51 +08:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
|
|
|
MainWindow w;
|
|
|
|
w.show();
|
2023-08-30 20:59:44 +08:00
|
|
|
// pthread_t t1,t2; //
|
|
|
|
// pthread_create(&t1,NULL,getTimerThreadFunc,(void*)&w);
|
|
|
|
// pthread_create(&t2,NULL,readPipeMSG,(void*)&w);
|
|
|
|
// pthread_join(t1,NULL);
|
|
|
|
// pthread_join(t2,NULL);
|
|
|
|
|
2023-08-29 17:08:51 +08:00
|
|
|
return a.exec();
|
|
|
|
}
|
2023-08-30 20:59:44 +08:00
|
|
|
|
|
|
|
void *getTimerThreadFunc(void *arg)
|
|
|
|
{
|
|
|
|
MainWindow *p = (MainWindow *)arg;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
// 发送获取的当前时间的命令
|
|
|
|
// 发送 get_time_pos 命令到管道中
|
|
|
|
write(p->fifo_fd, "get_time_pos\n", strlen("get_time_pos\n"));
|
|
|
|
usleep(500*1000); // 休眠 0.5 秒
|
|
|
|
|
|
|
|
// 发送获取当前歌曲进度的命令
|
|
|
|
write(p->fifo_fd,"get_percent_pos\n",strlen("get_percent_pos\n"));
|
|
|
|
usleep(500*1000); // 休眠 0.5 秒
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *readPipeMSG(void *arg)
|
|
|
|
{
|
|
|
|
MainWindow *p = (MainWindow *)arg;
|
|
|
|
|
|
|
|
// 不停的获取无名管道的数据
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
char buf[256] = "";
|
|
|
|
int ret = read(p->fd[0], buf, sizeof(buf)); // 从无名管道读取内容到 buf
|
|
|
|
if(ret > 0)
|
|
|
|
{
|
|
|
|
// 判断消息的类型 :
|
|
|
|
// 如果消息是 "当前歌曲播放时间位置"
|
|
|
|
if(strncmp(buf,"ANS_TIME_POSITION",strlen("ANS_TIME_POSITION")) == 0)
|
|
|
|
{
|
|
|
|
int time = 0;
|
|
|
|
sscanf(buf,"ANS_TIME_POSITION=%d",&time); // 从数据流 buf 中读取时间到 time
|
|
|
|
// 给 UI 发送当前时间信号
|
|
|
|
emit p->currentTimeSignal(time);
|
|
|
|
}
|
|
|
|
// 如果消息是 "当前歌曲播放进度"
|
|
|
|
else if(strncmp(buf,"ANS_PERCENT_POSITION", strlen("ANS_PERCENT_POSITION")) == 0)
|
|
|
|
{
|
|
|
|
int currentProgress = 0;
|
|
|
|
sscanf(buf, "ANS_PERCENT_POSITION=%d", ¤tProgress);
|
|
|
|
// 给 UI 发送进度信号
|
|
|
|
emit p->currentProgressSignal(currentProgress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|