应shenqiren朋友的要求,我贴一段我自己播放OGG音乐的代码。
我的代码没经过仔细的设计,写的也很随意,希望大家帮我修正一下。
(写的时候参考了粘土游戏库的代码)。
头文件:
- #include #include #include #include #include #include #include #pragma comment(lib,"dsound.lib")#pragma comment(lib,"dxguid.lib")#pragma comment(lib,"winmm.lib")class ljmMusicBuffer_DSound : public ljmMusicBuffer{public: ljmMusicBuffer_DSound(IDirectSound8* pDS); ~ljmMusicBuffer_DSound(); bool LoadOggFile(const char* szFileName); void Play(bool bLoop); void Stop(void); void Pause(void); void Reset(void); void SetVolume(float vol); bool IsPlaying(void);protected: LPDIRECTSOUND8 m_pDS; LPDIRECTSOUNDBUFFER m_pBuffer; LONG m_lVolume; WAVEFORMATEX m_wfx; DWORD m_dwWritePos; OggVorbis_File* m_pVorbisFile; string m_strCurFile; bool m_bMono ; long m_lRate; int current_section; bool m_bLoop; bool m_bFinished;// static const int BUFFERSIZE = 8192; UINT m_TimerID; void Clear(void); void FillBuffer(void); static void CALLBACK OnTimerCB(UINT uID, UINT uMsg,DWORD_PTR pUserData, DWORD_PTR dwParam1, DWORD_PTR dwParam2);};
复制代码 |
|