Crystal Space
Welcome, Guest. Please login or register.
April 18, 2014, 12:32:50 pm

Login with username, password and session length
Search:     Advanced search
8990 Posts in 2037 Topics by 7595 Members
Latest Member: Rejestruj1989
* 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 1909 times)
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
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:

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

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!

cheers!
Logged
Vincent
Full Member
***
Posts: 191


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

Hi,

  does that work better ?

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

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.).
Logged
maharaja
Jr. Member
**
Posts: 52

t.javed@hotmail.com
View Profile Email
« Reply #2 on: January 04, 2009, 08:22:45 am »

Hi,

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,
     CS_SND3D_ABSOLUTE);
  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:
<sounds>
    <sound name="bgmusic" file="/std/data/tada.wav" />
 </sounds>


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.

Thanks!


« Last Edit: January 04, 2009, 08:27:48 am by maharaja » Logged
res
Develazyoper
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: http://crystalspace3d.org/docs/online/api/structiSndSysManager.html
Logged
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 6.206 seconds with 16 queries.