19,468
社区成员
发帖
与我相关
我的任务
分享
#include"ENmultimedia.h"
bool ENmultimedia::LHxxLOAD_MULTIMEDIA(char *name,char *Tname)
{
iter=LHxxITERATOR_LIST(Tname,"NO");
if(iter!=NULL)
{
return S_FALSE;
}
char ss[100]="";
ENmultimediaData temp;
strcpy(temp.Name,Tname);
temp.WavOb=NULL;
temp.MultOb=new MultimediaData();
// DirectShow interfaces
temp.MultOb->pGB = NULL;
temp.MultOb->pMC = NULL;
temp.MultOb->pME = NULL;
temp.MultOb->pVW = NULL;
temp.MultOb->pBA = NULL;
temp.MultOb->pBV = NULL;
temp.MultOb->pMS = NULL;
temp.MultOb->pMP = NULL;
temp.MultOb->pFS = NULL;
temp.MultOb->g_bAudioOnly=FALSE;
temp.MultOb->g_bFullscreen=FALSE;
temp.MultOb->g_dwGraphRegister=0;
temp.MultOb->g_psCurrent=Stopped;
temp.MultOb->g_lVolume=VOLUME_FULL;
temp.WavOb=NULL;
HRESULT hr;
// If no filename specified by command line, show file open dialog
if(temp.MultOb->FileName[0]== L'\0')
{
TCHAR szFilename[MAX_PATH];
// If no filename was specified on the command line, then our video
// window has not been created or made visible. Make our main window
// visible and bring to the front to allow file selection.
//ShowWindow(hWnd, SW_SHOWNORMAL);
SetForegroundWindow(hWnd);
strcpy(szFilename,name);
// This sample does not support playback of ASX playlists.
// Since this could be confusing to a user, display a warning
// message if an ASX file was opened.
if (_tcsstr((_tcslwr(szFilename)), TEXT(".asx")))
{
return false;
}
// This sample does not offer support for Windows Media playback.
// The PlayWndASF and Jukebox samples demonstrate how to add a
// Windows Media certificate handler to your app, along with giving
// example code to load and connect the ASF Reader source filter.
// To prevent problems with using the older (default) ASF reader here,
// simply disable loading of ASF,WMA,WMV files.
if (IsWindowsMediaFile(szFilename))
{
_stprintf(ss,"(加载出错<不是所支持的文件类型>)LHxxLOAD_MULTIMEDIA:%s",name);
MessageBox(hWnd, ss, "error sound", MB_OK);
return false;
}
lstrcpy(temp.MultOb->FileName, szFilename);
}
// Reset status variables
temp.MultOb->g_psCurrent = Stopped;
temp.MultOb->g_lVolume = VOLUME_FULL;
SoundOb.push_back(temp);
// Start playing the media file
hr = PlayMovieInWindow(temp.MultOb->FileName,Tname);
// If we couldn't play the clip, clean up
if (FAILED(hr))
{
LHxxFREE_MULTIMEDIA(Tname);
}
LHxxSTOP_MULTIMEDIA(Tname);
return true;
}
void ENmultimedia::LHxxPLAY_MULTIMEDIA(char *Tname,int playmode)
{
iter=LHxxITERATOR_LIST(Tname,"LHxxPLAY_MULTIMEDIA()");
if(iter==NULL)
{
return;
}
iter->MultOb->PlayMode=playmode;
//重新开始播放
if(iter->MultOb->g_psCurrent == Stopped || iter->MultOb->g_psCurrent==End)
{
LHxxRESET_MULTIMEDIA(Tname);
}
iter->MultOb->g_psCurrent=Running;
iter->MultOb->pMC->Run();
}
void ENmultimedia::LHxxSTOP_MULTIMEDIA(char *Tname)
{
iter=LHxxITERATOR_LIST(Tname,"LHxxSTOP_MULTIMEDIA()");
if(iter==NULL)
{
return;
}
if(iter->MultOb->g_psCurrent==End)
{
return;
}
iter->MultOb->g_psCurrent=Stopped;
iter->MultOb->pMC->Stop();
}
void ENmultimedia::LHxxPAUSE_MULTIMEDIA(char *Tname)
{
iter=LHxxITERATOR_LIST(Tname,"LHxxPAUSE_MULTIMEDIA()");
if(iter==NULL)
{
return;
}
if (!iter->MultOb->pMC)
{
return;
}
//是stop状态时,不处理
if(iter->MultOb->g_psCurrent==Stopped || iter->MultOb->g_psCurrent==End)
{
return;
}
// Toggle play/pause behavior
if((iter->MultOb->g_psCurrent == Paused))//重按暂停时,播放
{
if (SUCCEEDED(iter->MultOb->pMC->Run()))
{
iter->MultOb->g_psCurrent = Running;
}
}
else
{
if (SUCCEEDED(iter->MultOb->pMC->Pause()))
{
iter->MultOb->g_psCurrent = Paused;
}
}
}
static int percent=0;
void LoadingThread(void *p)
{
percent=0;
list<ENmultimediaData>::iterator *iter=(list<ENmultimediaData>::iterator*)(p);
// (*iter)->MultOb->g_psCurrent=Running;
(*iter)->MultOb->g_psCurrent=Paused;
(*iter)->MultOb->pMC->Run();
(*iter)->MultOb->g_psCurrent=Running;
percent=100;
if(percent==100)
{
_endthreadex(NULL);
}
cout<<"退出线程1:"<<endl;
return;
}
//加载资源
unsigned int __stdcall LoadingThread1(void *p)//加载游戏资源
{
percent=0;
list<ENmultimediaData>::iterator *iter=(list<ENmultimediaData>::iterator*)(p);
// (*iter)->MultOb->g_psCurrent=Running;
(*iter)->MultOb->g_psCurrent=Paused;
(*iter)->MultOb->pMC->Run();
(*iter)->MultOb->g_psCurrent=Running;
percent=100;
if(percent==100)
{
_endthreadex(NULL);
}
cout<<"退出线程2:"<<endl;
return 0;
}
int ENmultimedia::LHxxSTATE_MULTIMEDIA(char *Tname)//检测是否在播放中
{
iter=LHxxITERATOR_LIST(Tname,"NO");
if(iter==NULL)
{
return false;
}
LHxxHANDLE_GRAPHEVENT(Tname);
if(iter->MultOb->PlayMode==1)//循环播放
{
if(iter->MultOb->g_psCurrent==End)
{
LHxxRESET_MULTIMEDIA(Tname);
iter->MultOb->g_psCurrent=Running;
iter->MultOb->pMC->Run();
/*
iter->MultOb->g_psCurrent=Paused;
static unsigned long t=0;
LHxxRESET_MULTIMEDIA(Tname);
iter->MultOb->g_psCurrent=Paused;
_beginthreadex((void*)t,t,&LoadingThread1,(unsigned int *)&iter,(unsigned)t,(unsigned*)t);
if(percent==100)
{
percent=0;
}
*/
/*
iter->MultOb->g_psCurrent=Paused;
static unsigned long t=0;
LHxxRESET_MULTIMEDIA(Tname);
iter->MultOb->g_psCurrent=Paused;
_beginthread(&LoadingThread,t,(unsigned int *)&iter);
if(percent==100)
{
percent=0;
}
*/
}
}
//0:stop; 1:pause; 2:playing; 3:ini
// cout<<"iter->MultOb->g_psCurrent:"<<iter->MultOb->g_psCurrent<<endl;
return iter->MultOb->g_psCurrent;
}
bool ENmultimedia::LHxxFREE_MULTIMEDIA(char *Tname)
{
iter=LHxxITERATOR_LIST(Tname,"LHxxFREE_MULTIMEDIA()");
if(iter==NULL)
{
return false;
}
LHxxFREE_CLIP(Tname);
delete iter->MultOb;
iter->MultOb=NULL;
SoundOb.erase(iter);
return true;
}
void ENmultimedia::LHxxRESET_MULTIMEDIA(char *Tname)
{
iter=LHxxITERATOR_LIST(Tname,"LHxxRESET_MULTIMEDIA()");
if(iter==NULL)
{
return;
}
LONGLONG pos=0;
// Run the graph to play the media file
iter->MultOb->pMS->SetPositions(&pos, AM_SEEKING_AbsolutePositioning ,NULL, AM_SEEKING_NoPositioning);
}
m_Video = MCIWndCreate(this->GetSafeHwnd(), AfxGetInstanceHandle(), WS_CHILD | WS_VISIBLE | MCIWNDF_NOMENU | MCIWNDF_NOPLAYBAR, "C:\\AVDemo.avi");
MCIWndPlay(m_Video);