⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directshowmusic.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// DirectShowMusic.cpp: implementation of the CDirectShowMusic class.
//
//////////////////////////////////////////////////////////////////////

#include "DirectShowMusic.h"
#include <algorithm> // for std::find

namespace AudioEngine {

std::vector<CDirectShowMusic *> CDirectShowMusic::m_AllDSMusicObjects;

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDirectShowMusic::CDirectShowMusic(CAudioManager *mgr) : CSound(mgr)
{
  m_GraphBuilder = NULL;
  m_MediaControl = NULL;
  m_MediaEventEx = NULL;
  m_AllDSMusicObjects.push_back(this);
}

CDirectShowMusic::~CDirectShowMusic()
{
  SAFE_RELEASE(m_MediaControl);
  SAFE_RELEASE(m_MediaEventEx);
  SAFE_RELEASE(m_GraphBuilder);

  std::vector<CDirectShowMusic *>::iterator i = 
    std::find(m_AllDSMusicObjects.begin(), m_AllDSMusicObjects.end(), this);
  if (i != m_AllDSMusicObjects.end()) m_AllDSMusicObjects.erase(i);
}

bool CDirectShowMusic::Play()
{
  if (m_MediaControl == NULL) return(false);
  ThrowIfFailed(m_MediaControl->Run(), "CDirectShowMusic::Play(): Run failed.");
  m_IsPlaying = true;
  return(true);
}

bool CDirectShowMusic::Stop()
{
  if (m_MediaControl == NULL) return(false);
  ThrowIfFailed(m_MediaControl->Stop(), "CDirectShowMusic::Stop(): Stop failed.");
  m_IsPlaying = false;
  return(true);
}

bool CDirectShowMusic::IsPlaying()
{
  return(m_IsPlaying);
}

void CDirectShowMusic::DispatchDirectShowNotifications()
{
  for (std::vector<CDirectShowMusic *>::iterator i = m_AllDSMusicObjects.begin(); i != m_AllDSMusicObjects.end(); ++i) {
    (*i)->ProcessMyDirectShowNotifications();
  }
}

void CDirectShowMusic::ProcessMyDirectShowNotifications()
{
  long    eventcode, param1, param2;
  while (m_MediaEventEx->GetEvent(&eventcode, &param1, &param2, 0) == S_OK) {
    if (eventcode == EC_COMPLETE) { 
      m_IsPlaying = false;
    }
    m_MediaEventEx->FreeEventParams(eventcode, param1, param2);
  }
}


} // namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -