forked from CountMurphy/QTalarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.cpp
80 lines (67 loc) · 1.63 KB
/
alarm.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "alarm.h"
#include "fileio.h"
#include <QMediaPlayer>
#include <QString>
#include <QDir>
Alarm::Alarm(QObject *parent) :
QObject(parent)
{
media = new QMediaPlayer(this);
this->_DefaultPath=QDir::tempPath()+"/QTalarm.ogg";
this->_isPlaying=false;
this->_Pause=new QTimer(this);
this->canResume=true;
connect(this->_Pause,SIGNAL(timeout()),this,SLOT(Resume()));
}
void Alarm::Start(bool useCustom)
{
if(useCustom)
{
media->setMedia(QUrl::fromLocalFile(this->_CustPath));
this->UsingCustomPath=true;
}else{
FileIO::ExtractAudio();
media->setMedia(QUrl::fromLocalFile(this->_DefaultPath));
this->UsingCustomPath=false;
}
media->play();
connect(media,SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),this,SLOT(RepeatAllTheThings(QMediaPlayer::MediaStatus)));
this->_isPlaying=true;
}
void Alarm::Stop()
{
media->stop();
this->_Pause->start(60000);
this->_isPlaying=false;
}
void Alarm::RepeatAllTheThings(QMediaPlayer::MediaStatus state)
{
if(state==QMediaPlayer::EndOfMedia)
{
if(this->UsingCustomPath)
{
media->setMedia(QUrl::fromLocalFile(this->_CustPath));
}else{
media->setMedia(QUrl::fromLocalFile(this->_DefaultPath));
}
media->play();
}
}
bool Alarm::isPlaying()
{
return this->_isPlaying;
}
void Alarm::SetCustomPath(QString CustPath)
{
this->_CustPath=CustPath;
}
void Alarm::Resume()
{
this->canResume=true;
this->_Pause->stop();
}
void Alarm::SetVolume(int Volume)
{
media->setVolume(Volume);
FileIO::SaveVolume(Volume);
}