代码拉取完成,页面将自动刷新
#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;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。