-
Notifications
You must be signed in to change notification settings - Fork 26
/
sound.cpp
executable file
·70 lines (64 loc) · 1.96 KB
/
sound.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
#include "sound.h"
Sound::Sound(QWidget *parent) :
QWidget(parent)
{
fac=new Factory();
InterfaceBGM=fac->CreateQMediaPlayer(this,QUrl("qrc:/music/music/interface_main_theme.mp3"),50);
InterfaceBGM->play();
DungeonBGM=fac->CreateQMediaPlayer(this,QUrl("qrc:/music/music/main_theme.mp3"),50);
FightSound=fac->CreateQMediaPlayer(this,QUrl("qrc:/music/music/brick_smash.mp3"),80);
DungeonSoundList=fac->CreateQMediaPlaylist(this);
DungeonSound=fac->CreateQMediaPlayer(this,QUrl(""),80);
DungeonSound->setPlaylist(DungeonSoundList);
InterfaceBGMTimer=new QTimer(this);
connect(InterfaceBGMTimer,SIGNAL(timeout()),this,SLOT(CheckInterfaceBGMstate()));
InterfaceBGMTimer->start(10);
DungeonBGMTimer=new QTimer(this);
connect(DungeonBGMTimer,SIGNAL(timeout()),this,SLOT(CheckDungeonBGMstate()));
FightSoundTimer=new QTimer(this);
connect(FightSoundTimer,SIGNAL(timeout()),this,SLOT(CheckFightSoundstate()));
DungeonSoundTimer=new QTimer(this);
connect(DungeonSoundTimer,SIGNAL(timeout()),this,SLOT(SoundStop()));
musicChange=true;
}
void Sound::CheckInterfaceBGMstate()
{
if(InterfaceBGM->state()==0)//0代表停止 1代表播放 2代表暂停
{
InterfaceBGM->play();
}
}
void Sound::CheckDungeonBGMstate()
{
if(DungeonBGM->state()==0)//0代表停止 1代表播放 2代表暂停
{
DungeonBGM->play();
}
}
void Sound::CheckFightSoundstate()
{
if(FightSound->state()==0)
FightSound->play();
}
void Sound::SoundStop()
{
DungeonSound->stop();
DungeonSoundTimer->stop();
}
void Sound::SoundPlay(int CurrentIndex)
{
DungeonSoundList->setCurrentIndex(CurrentIndex);
DungeonSound->play();
if(CurrentIndex==3)
{
DungeonSoundTimer->start(400);
}
else if(CurrentIndex==5)
{
DungeonSoundTimer->start(3000);
}
else
{
DungeonSoundTimer->start(1000);
}
}