-
Notifications
You must be signed in to change notification settings - Fork 35
/
musicplayer.cpp
68 lines (62 loc) · 1.76 KB
/
musicplayer.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
#include "musicplayer.h"
#include "dirent.h"
#include <sys/types.h>
Musicplayer::Musicplayer() //¶ÁÈ¡ÒôÀÖÎļþ
{
DIR* dir;
struct dirent* ptr;
dir = opendir("resources\\music");
while ((ptr = readdir(dir)) != NULL) {
std::string s = ptr->d_name;
if (s.length() <= 4) continue;
if (s.substr(s.length() - 4, s.length()) != ".mp3" && s.substr(s.length() - 4, s.length()) != ".wav") continue;
MUSIC* m = new MUSIC;
m->OpenFile((std::string("resources\\music\\") + s).c_str());
s = s.erase(s.length() - 4, s.length());
musics[std::string("music-") + s] = m;
}
dir = opendir("resources\\sound");
while ((ptr = readdir(dir)) != NULL) {
std::string s = ptr->d_name;
if (s.length() <= 4) continue;
if (s.substr(s.length() - 4, s.length()) != ".mp3" && s.substr(s.length() - 4, s.length()) != ".wav") continue;
MUSIC* m = new MUSIC;
m->OpenFile((std::string("resources\\sound\\") + s).c_str());
s = s.erase(s.length() - 4, s.length());
musics[std::string("sound-") + s] = m;
}
}
bool Musicplayer::play(std::string s)
{
auto p = musics.find(s);
if (p == musics.end()) return false;
p->second->Play(0);
return true;
}
bool Musicplayer::stop(std::string s)
{
auto p = musics.find(s);
if (p == musics.end()) return false;
p->second->Stop();
return true;
}
bool Musicplayer::checkend(std::string s)
{
auto p = musics.find(s);
if (p == musics.end()) return false;
return p->second->GetPlayStatus() == MUSIC_MODE_STOP;
}
bool Musicplayer::isplay(std::string s)
{
auto p = musics.find(s);
if (p == musics.end()) return false;
return p->second->GetPlayStatus() == MUSIC_MODE_PLAY;
}
bool Musicplayer::SetVolume(std::string s, double v)
{
auto p = musics.find(s);
if (p == musics.end()) return false;
p->second->SetVolume(v);
return true;
}
Musicplayer musicplayer;