-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioTask.h
58 lines (53 loc) · 1.42 KB
/
AudioTask.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef AUDIOTASK_H
#define AUDIOTASK_H
#include "Task.h"
#include "WAVFile.h"
#include <QAudioOutput>
#include <QSlider>
#include <QTextStream>
class AudioTask : public Task
{
public:
AudioTask(QString a, QString b, QFileInfo c, QAudioOutput* d, QString e) : Task(a, b, c), audio(d), sampleRate(e)
{
taskType = a;
taskName = b;
taskInfo = c;
taskProgress = 0;
}
~AudioTask()
{
record();
delete audio;
delete file;
delete timeSlider;
}
QAudio::State getState(){ return audio ? audio->state() : QAudio::StoppedState; }
void start(){ if (getState() != QAudio::ActiveState) audio->start(); }
void pause() { if (getState() == QAudio::ActiveState) audio->stop(); }
void stop() { if (getState() != QAudio::StoppedState) audio->blockSignals(true); }
void record()
{
QFile file("task.log");
if (!file.open(QIODevice::ReadWrite | QIODevice::Append)) return;
QTextStream in(&file);
QString str = QString::fromLocal8Bit("任务创建时间: ") + taskTime.toString()
+QString::fromLocal8Bit("\n文件绝对路径: ") + taskInfo.absoluteFilePath()
+ QString::fromLocal8Bit("\n文件大小:") + QString::number(taskInfo.size())
+ QString::fromLocal8Bit("\n信号:") + taskName;
in << str << "\n";
file.close();
}
void setState()
{
if (getState() == QAudio::ActiveState)audio->stop();
else audio->start();
}
public:
QString sampleRate;
qint64 size;
WAVFile *file;
QAudioOutput* audio;
QSlider *timeSlider;
};
#endif