Crystal Space
Welcome, Guest. Please login or register.
October 19, 2017, 11:09:30 pm

Login with username, password and session length
Search:     Advanced search
9063 Posts in 2051 Topics by 77350 Members
Latest Member: Tanninhalber212
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Playing music from XML map file.. help!
« previous next »
Pages: [1] Print
Author Topic: Playing music from XML map file.. help!  (Read 3162 times)
Jr. Member
Posts: 52
View Profile Email
« on: December 08, 2008, 08:00:47 pm »

Hi all, and happy holidays to everyone. Here's my annual posting(lol)

To this day I have not understood how do you play a sound from an XML file?
In the good old articles on community site (Structure of an XML world file- part 1 & 2) it says to add:

<sound name="tada.wav">

But this dont work! The message I get is: "Unable to create sound data from /std/data/tada.wav"

I can very well play music from my C++ files but what I NEED to know is how can I play music from XML file.
The music file is perfectly ok.

Using CS & CEL 1.2.1 on WinXP with Win32 1.2_002 libraries. Everything working fine!

Any help would be highly appreciated!

Full Member
Posts: 191

View Profile WWW
« Reply #1 on: December 19, 2008, 11:04:29 pm »


  does that work better ?

    <sound name="tada.wav" file="/std/data/tada.wav" />

Note that doesn't "play" the sound, it only loads it and assign it a name, so you can find and play it from code (no need to load the file beforehand)...
If you use CEL and pcsound property class, you might be able to play it, but then it all depends on how your entity is set up (behaviour, etc.).
Jr. Member
Posts: 52
View Profile Email
« Reply #2 on: January 04, 2009, 08:22:45 am »


At present I'm playing background music from code as follows:

bool ClientMain::LoadSound ()
  const char* fname = "/std/data/tada.wav";
  csRef<iVFS> vfs = csQueryRegistry<iVFS> (GetObjectRegistry ());

  csRef<iDataBuffer> soundbuf = vfs->ReadFile (fname);
  if (!soundbuf)
    return ReportError ("Can't load file '%s'!", fname);

  csRef<iSndSysData> snddata = sndloader->LoadSound (soundbuf);
  if (!snddata)
    return ReportError ("Can't load sound '%s'!", fname);

  csRef<iSndSysStream> sndstream = sndrenderer->CreateStream (snddata,
  if (!sndstream)
    return ReportError ("Can't create stream for '%s'!", fname);

  sndsource = sndrenderer->CreateSource (sndstream);
  if (!sndsource)
    return ReportError ("Can't create source for '%s'!", fname);
  sndsource3d = scfQueryInterface<iSndSysSourceSoftware3D> (sndsource);

  sndsource3d->SetPosition (GetSoundPos (0));
  sndsource3d->SetVolume (1.0f);

  sndstream->SetLoopState (CS_SNDSYS_STREAM_LOOP);
  sndstream->Unpause ();

  //sndsrc->SetVolume( 1.0 );

  return true;

Now... if I instead "load" the music from XML file as:
    <sound name="bgmusic" file="/std/data/tada.wav" />

How do I access '´bgmusic' from the code and what I have to do to 'play' it?
Sorry if it sounds too basic... never tried like this before.


« Last Edit: January 04, 2009, 08:27:48 am by maharaja » Logged
CS Developer
Full Member
Posts: 206

View Profile Email
« Reply #3 on: January 04, 2009, 08:54:17 pm »

You should be able to query that sound with the FindSoundByName() method from the iSndSysManager instance in the object registry. See:
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 5.154 seconds with 16 queries.