Created
November 6, 2011 19:51
-
-
Save flyingmutant/1343380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ISound | |
{ | |
virtual ~ISound() {}; | |
//скорость потока | |
virtual double bitrate() const = 0; | |
//полезные методы | |
... | |
}; | |
typedef boost::shared_ptr<ISound> sound_ptr_t; | |
struct ISoundCard | |
{ | |
virtual ~ISoundCard() {} | |
//воспроизвести звуковой поток через звуковую карту | |
virtual void Play(sound_ptr_t) = 0; | |
//полезные методы | |
... | |
}; | |
typedef boost::shared_ptr<ISoundCard> soundcard_ptr_t; | |
// фабрики (опционально, можно их сделать методами какого-нибудь интерфейса вроде ISoundSystem) | |
sound_ptr_t load_file(std::string const& filename); | |
soundcard_ptr_t open_soundcard(...); | |
class MediaPlayer | |
{ | |
public: | |
MediaPlayer(): | |
soundcard_(open_soundcard(...)) | |
{ | |
//Инициализируем остальные ресурсы | |
... | |
} | |
~MediaPlayer() | |
{ | |
//Освобождаем остальные ресурсы | |
... | |
} | |
//Загрузка нового звуковой файл в плейер | |
void Open(const std::string& filename) | |
{ | |
playlist_.push_back(load_file(filename)); | |
} | |
//Воспроизведение звука | |
void Play(sound_ptr_t sound) | |
{ | |
soundcard_->Play(sound); | |
} | |
//Другие полезные методы | |
... | |
private: | |
soundcard_ptr_t soundcard_; | |
std::vector<sound_ptr_t> playlist_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment