/////////////////////////////////////////////////////////////////////////////////////////// // BackgroundSound.h // // Definition of the BackgroundSound class, which extends Sound to handle DirectShow- // compatible files, changes the DirectMusic playback mode to 'primary' (necessary to play // General MIDI files correctly) and adds the capability to detect when the sound has // finished playing. #pragma once #include "Sound.h" using namespace System; using namespace System::ComponentModel; namespace Sunlight { namespace DirectX { namespace SoundMusic { // Contains a background music file for DirectMusic or DirectShow, with an end-of-file event. __gc public class BackgroundSound : public Sound { protected: // DirectShow source filters bool m_bDirectShow; // true if sound should be playing bool m_bPlaying; IGraphBuilder __nogc *m_pGraphBuilder; IMediaControl __nogc *m_pMediaControl; IMediaSeeking __nogc *m_pMediaSeeking; IMediaEventEx __nogc *m_pMediaEventEx; // Thread to handle end-of-file notifications Threading::Thread *m_pRepeatThread; // Event handle for end-of-file notifications HANDLE m_heventRepeat; // Thread function for looking for end-of-file void OnEndThread(); // Called when the ParentWindow is closed. void OnFormClosed(Object *sender, EventArgs *e); // Called when the ParentWindow is activated. void OnFormActivated(Object *sender, EventArgs *e); // Called when the ParentWindow is deactivated. void OnFormDeactivated(Object *sender, EventArgs *e); // Load this sound object into memory. virtual void Load(); // Unload this object from memory. virtual void Unload(); public: BackgroundSound(); ~BackgroundSound(); // Play this object. virtual void Play(); // Stop the playback of this object. virtual void Pause(); // Stop the playback of this object and return to the beginning. virtual void Stop(); // Called when sound finishes playing. __event EventHandler *Finished; }; } } }