13 Star 72 Fork 26

tuxiaobei/mario

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
musicplayer.cpp 1.76 KB
一键复制 编辑 原始数据 按行查看 历史
tuxiaobei 提交于 2022-01-04 11:45 . 更新readme.md,添加注释
#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;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/tuxiaobei/mario.git
[email protected]:tuxiaobei/mario.git
tuxiaobei
mario
mario
master

搜索帮助