Example #1
0
void play(const char* name, bool stream=false)
{
  // Only load streams if the backend supports it
  if(stream && !mg.canLoadStream)
    return;

  cout << "Playing " << name;
  if(stream) cout << " (from stream)";
  cout << "\n";

  SoundPtr snd;

  try
    {
      if(stream)
        snd = mg.load(StreamPtr(new FileStream(name)));
      else
        snd = mg.load(name);

      snd->play();

      while(snd->isPlaying())
        {
          usleep(10000);
          if(mg.needsUpdate) mg.update();
        }
    }
  catch(exception &e)
    {
      cout << "  ERROR: " << e.what() << "\n";
    }
}
Example #2
0
    bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const
    {
      PtrMap::const_iterator it = sounds.find(ptr);
      if(it != sounds.end())
        {
          IDMap::const_iterator it2 = it->second.find(id);
          if(it2 != it->second.end())
            {
              // Get a shared_ptr from the weak_ptr
              SoundPtr snd = it2->second.lock();;

              // Is it still alive?
              if(snd)
                {
                  // Then return its status!
                  return snd->isPlaying();
                }
            }
        }
      // Nothing found, sound is not playing
      return false;
    }