1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:23:51 +00:00

Restore music playback

This commit is contained in:
Chris Robinson 2012-03-20 11:31:13 -07:00
parent 5ae47f783e
commit fc27d5cc19
2 changed files with 15 additions and 3 deletions

View file

@ -157,6 +157,7 @@ namespace MWSound
void SoundManager::streamMusic(const std::string& filename) void SoundManager::streamMusic(const std::string& filename)
{ {
std::cout <<"Playing "<<filename<< std::endl;
try try
{ {
if(mMusic) if(mMusic)
@ -171,6 +172,14 @@ namespace MWSound
void SoundManager::startRandomTitle() void SoundManager::startRandomTitle()
{ {
Ogre::StringVectorPtr filelist;
filelist = mResourceMgr->findResourceNames(Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
"Music/"+mCurrentPlaylist+"/*");
if(!filelist->size())
return;
int i = rand()%filelist->size();
streamMusic((*filelist)[i]);
} }
bool SoundManager::isMusicPlaying() bool SoundManager::isMusicPlaying()
@ -178,8 +187,10 @@ namespace MWSound
return mMusic && mMusic->isPlaying(); return mMusic && mMusic->isPlaying();
} }
void SoundManager::playPlaylist(std::string playlist) void SoundManager::playPlaylist(const std::string &playlist)
{ {
mCurrentPlaylist = playlist;
startRandomTitle();
} }
void SoundManager::say(MWWorld::Ptr ptr, const std::string& filename) void SoundManager::say(MWWorld::Ptr ptr, const std::string& filename)
@ -385,7 +396,7 @@ namespace MWSound
timePassed = 0.0f; timePassed = 0.0f;
// Make sure music is still playing // Make sure music is still playing
if(!mMusic || !mMusic->isPlaying()) if(!isMusicPlaying())
startRandomTitle(); startRandomTitle();
Ogre::Camera *cam = mEnvironment.mWorld->getPlayer().getRenderer()->getCamera(); Ogre::Camera *cam = mEnvironment.mWorld->getPlayer().getRenderer()->getCamera();

View file

@ -44,6 +44,7 @@ namespace MWSound
std::auto_ptr<Sound_Output> mOutput; std::auto_ptr<Sound_Output> mOutput;
boost::shared_ptr<Sound> mMusic; boost::shared_ptr<Sound> mMusic;
std::string mCurrentPlaylist;
typedef boost::shared_ptr<Sound> SoundPtr; typedef boost::shared_ptr<Sound> SoundPtr;
typedef std::map<std::string,SoundPtr> IDMap; typedef std::map<std::string,SoundPtr> IDMap;
@ -83,7 +84,7 @@ namespace MWSound
bool isMusicPlaying(); bool isMusicPlaying();
///< Returns true if music is playing ///< Returns true if music is playing
void playPlaylist(std::string playlist); void playPlaylist(const std::string &playlist);
///< Start playing music from the selected folder ///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist /// \param name of the folder that contains the playlist