1 #include "FirstUiBuilder.h"
2 #include "SimpleSoundCanvas.h"
4 #include "FileLocator.h"
8 SimpleSoundCanvas::SimpleSoundCanvas() :
15 SimpleSoundCanvas::~SimpleSoundCanvas()
18 for (SoundMap_t::iterator iter
= m_soundMap
.begin (); iter
!= m_soundMap
.end (); ++iter
)
20 delete (*iter
).second
;
28 void SimpleSoundCanvas::Play( const char *name
)
33 SoundMap_t::const_iterator find_iter
= m_soundMap
.find (name
);
35 if (find_iter
== m_soundMap
.end ())
37 UINarrowString
filename (name
);
40 UINarrowString result
;
42 if ( FileLocator::gFileLocator ().findFile (filename
.c_str (), result
) == false)
45 FILE * fl
= fopen (result
.c_str (), "rb");
50 fseek (fl
, 0, SEEK_END
);
51 long len
= ftell (fl
);
52 fseek (fl
, 0, SEEK_SET
);
54 char * buf
= new char [len
];
56 if (!fread (buf
, len
, 1, fl
))
64 std::pair
<SoundMap_t::const_iterator
, bool> retval
= m_soundMap
.insert (SoundMap_t::value_type (name
, buf
));
66 find_iter
= retval
.first
;
69 PlaySound ((*find_iter
).second
, NULL
, SND_MEMORY
| SND_ASYNC
| SND_NOWAIT
| SND_NOSTOP
);