468 lines
7.2 KiB
C++
Executable File
468 lines
7.2 KiB
C++
Executable File
#include "StdAfx.h"
|
|
#include "TcpmpPlayer.h"
|
|
|
|
void FormatTcpmpString(char* pChar, tchar_t* pTChar)
|
|
{
|
|
DWORD dwLen = MultiByteToWideChar(CP_OEMCP,0,pChar,-1,NULL,0);
|
|
|
|
MultiByteToWideChar(CP_OEMCP,0,pChar,-1,(LPWSTR)pTChar,dwLen);
|
|
}
|
|
|
|
CTcpmpPlayer::CTcpmpPlayer(void)
|
|
{
|
|
m_Player = NULL;
|
|
// m_HasFile = FALSE;
|
|
}
|
|
|
|
CTcpmpPlayer::~CTcpmpPlayer(void)
|
|
{
|
|
}
|
|
|
|
// ³õʼ»¯TCPMP²¥·ÅÆ÷
|
|
bool CTcpmpPlayer::Init(char* pVersion,int iVer,BOOL bVideo, void* pVideoWnd)
|
|
{
|
|
tchar_t ProgramName[MAX_PATH];
|
|
tchar_t ProgramCmd[MAX_PATH];
|
|
tchar_t ProgrameVer[MAX_PATH];
|
|
|
|
|
|
char pCharProg[] = TCPMPCLASS;
|
|
char pCharCmd[] = "";
|
|
|
|
FormatTcpmpString(pCharProg,ProgramName);
|
|
FormatTcpmpString(pVersion,ProgrameVer);
|
|
FormatTcpmpString(pCharCmd,ProgramCmd);
|
|
|
|
if (!Context_Init(ProgramName,ProgramName,iVer,ProgramCmd,NULL))
|
|
{
|
|
AfxMessageBox(L"Init Player Core Error!");
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (pVideoWnd)
|
|
{
|
|
Context_Wnd(pVideoWnd);
|
|
}
|
|
else
|
|
{
|
|
Context_Wnd((void*)1);
|
|
}
|
|
|
|
context* p = Context();
|
|
|
|
if (p)
|
|
{
|
|
m_Player = (player*)(p->Player);
|
|
}
|
|
|
|
if (bVideo)
|
|
{
|
|
int Int = CONSOLE_ID;
|
|
m_Player->Set(m_Player,PLAYER_VOUTPUTID,&Int,sizeof(Int));
|
|
|
|
node* Color = NodeEnumObject(NULL,COLOR_ID);
|
|
Int = 8;
|
|
Color->Set(Color,COLOR_BRIGHTNESS,&Int,sizeof(Int));
|
|
Int = 32;
|
|
Color->Set(Color,COLOR_CONTRAST,&Int,sizeof(Int));
|
|
Int = 24;
|
|
Color->Set(Color,COLOR_SATURATION,&Int,sizeof(Int));
|
|
|
|
|
|
((player*)m_Player)->Paint(m_Player,NULL,0,0);
|
|
}
|
|
|
|
|
|
bool_t b = 0;
|
|
m_Player->Set(m_Player,PLAYER_FULLSCREEN,&b,sizeof(bool_t));
|
|
|
|
b = 1;
|
|
|
|
m_Player->Set(m_Player, PLAYER_EXIT_AT_END,&b,sizeof(b));
|
|
|
|
b = 0;
|
|
m_Player->Set(m_Player, PLAYER_REPEAT,&b,sizeof(b));
|
|
|
|
int i = 0;
|
|
m_Player->Set(m_Player, PLAYER_LIST_COUNT, &i ,sizeof(i));
|
|
|
|
b = 1;
|
|
m_Player->Set(m_Player, PLAYER_PLAYATOPEN, &i , sizeof(i));
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
void CTcpmpPlayer::SetDisplayRect(rect* lRect)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
m_Player->Set(m_Player, PLAYER_RESETVIDEO,0,NULL);
|
|
m_Player->Set(m_Player,PLAYER_SKIN_VIEWPORT,lRect,sizeof(rect));
|
|
|
|
}
|
|
}
|
|
|
|
bool CTcpmpPlayer::Play(bool bPause)
|
|
{
|
|
bool_t Bool;
|
|
|
|
if (bPause)
|
|
{
|
|
Bool = 1;
|
|
}
|
|
else
|
|
{
|
|
Bool = 0;
|
|
}
|
|
|
|
if (m_Player && GetListFileNumber())
|
|
{
|
|
m_Player->Set(m_Player,PLAYER_PLAY,&Bool,sizeof(Bool));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void CTcpmpPlayer::Stop(void)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
m_Player->Set(m_Player,PLAYER_STOP,NULL,0);
|
|
}
|
|
}
|
|
|
|
BOOL CTcpmpPlayer::IsPlaying(void)
|
|
{
|
|
bool_t b;
|
|
|
|
if (GetListFileNumber() <= 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (m_Player)
|
|
{
|
|
if (m_Player->Get(m_Player,PLAYER_PLAY,&b,sizeof(b)) == ERR_NONE && b)
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
tick_t CTcpmpPlayer::GetDuration(void)
|
|
{
|
|
tick_t time;
|
|
|
|
if (m_Player)
|
|
{
|
|
if (m_Player->Get(m_Player,PLAYER_DURATION,&time,sizeof(time)) == ERR_NONE && time >= 0)
|
|
{
|
|
return time/TICKSPERSEC;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int CTcpmpPlayer::GetVolume(void)
|
|
{
|
|
int volume;
|
|
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Get(m_Player,PLAYER_VOLUME,&volume,sizeof(volume)) == ERR_NONE)
|
|
{
|
|
return volume;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
bool CTcpmpPlayer::SetVolume(int iVolum)
|
|
{
|
|
if (iVolum > 100)
|
|
{
|
|
iVolum = 100;
|
|
}
|
|
|
|
if (iVolum < 0)
|
|
{
|
|
iVolum = 0;
|
|
}
|
|
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Set(m_Player,PLAYER_VOLUME,&iVolum,sizeof(iVolum)) == ERR_NONE)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CTcpmpPlayer::SetMute(bool bMute)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Set(m_Player,PLAYER_MUTE,&bMute,sizeof(bool_t)) == ERR_NONE)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CTcpmpPlayer::IsFullScreen()
|
|
{
|
|
bool_t bFull = false;
|
|
|
|
if (m_Player)
|
|
{
|
|
m_Player->Get(m_Player,PLAYER_FULLSCREEN,&bFull,sizeof(bool_t));
|
|
if (bFull)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool CTcpmpPlayer::SetFullScreen(bool bFull)
|
|
{
|
|
bool_t b = false;
|
|
|
|
if (bFull)
|
|
{
|
|
b = true;
|
|
}
|
|
|
|
m_Player->Set(m_Player,PLAYER_FULLSCREEN,&b,sizeof(bool_t));
|
|
m_Player->Set(m_Player, PLAYER_UPDATEVIDEO,0,NULL);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CTcpmpPlayer::GetMute(void)
|
|
{
|
|
bool bState;
|
|
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Get(m_Player,PLAYER_MUTE,&bState,sizeof(bool_t)) == ERR_NONE)
|
|
{
|
|
return bState;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int CTcpmpPlayer::SetCurrentPlayFile(char* pFileName)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
static tchar_t FileName[MAX_PATH];
|
|
FormatTcpmpString(pFileName,FileName);
|
|
|
|
PlayerAdd(m_Player,0,FileName,NULL);
|
|
m_Player->Set(m_Player,PLAYER_STOP,NULL,0);
|
|
|
|
return 0;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
bool CTcpmpPlayer::HasPlayFile(void)
|
|
{
|
|
return (GetListFileNumber() != 0);
|
|
}
|
|
|
|
tick_t CTcpmpPlayer::GetPossion(void)
|
|
{
|
|
tick_t time;
|
|
|
|
if (m_Player)
|
|
{
|
|
if (m_Player->Get(m_Player,PLAYER_POSITION,&time,sizeof(time)) == ERR_NONE && time >= 0)
|
|
{
|
|
return time/TICKSPERSEC;
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
bool CTcpmpPlayer::SetPossion(time_t tTime)
|
|
{
|
|
|
|
tTime *= TICKSPERSEC;
|
|
|
|
if (m_Player)
|
|
{
|
|
if (m_Player->Set(m_Player,PLAYER_POSITION,&tTime,sizeof(tTime)) == ERR_NONE)
|
|
{
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool CTcpmpPlayer::SetNotifyCallBack(LPVOID lpForm, LONG PlayerNotifyProc)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
notify Notify;
|
|
|
|
Notify.This = lpForm;
|
|
Notify.Func = (notifyfunc)PlayerNotifyProc;
|
|
m_Player->Set(m_Player,PLAYER_NOTIFY,&Notify,sizeof(Notify));
|
|
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
|
|
}
|
|
|
|
int CTcpmpPlayer::GetListFileNumber(void)
|
|
{
|
|
int i;
|
|
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Get(m_Player, PLAYER_LIST_COUNT, &i, sizeof(i)) == ERR_NONE)
|
|
{
|
|
return i;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
CString CTcpmpPlayer::GetListFileName(int iIndex)
|
|
{
|
|
CString str = TEXT("");
|
|
|
|
if (m_Player)
|
|
{
|
|
tchar_t FileName[MAX_PATH];
|
|
|
|
if(m_Player->Get(m_Player, PLAYER_LIST_URL + iIndex, FileName, sizeof(FileName)) == ERR_NONE)
|
|
{
|
|
str = CString((TCHAR*)((unsigned short*)FileName));
|
|
}
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
int CTcpmpPlayer::GetCurFileIndex(void)
|
|
{
|
|
int i;
|
|
|
|
if (m_Player)
|
|
{
|
|
if(m_Player->Get(m_Player, PLAYER_LIST_CURRENT, &i, sizeof(i)) == ERR_NONE)
|
|
{
|
|
return i;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int CTcpmpPlayer::AddFileFromDir(tchar_t* pDirName, tchar_t* pExtName, bool bCheckExt, int iDeep)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
int i = 0;
|
|
|
|
i = PlayerAddDir(m_Player,i,pDirName,pExtName,bCheckExt,iDeep);
|
|
|
|
/*CString str;
|
|
str.Format(TEXT("Add %d Files.\n"),i);
|
|
OutputDebugString(str);*/
|
|
|
|
return i;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
bool CTcpmpPlayer::Next(void)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
if ((m_Player->Set(m_Player,PLAYER_NEXT,NULL,0)) == ERR_NONE)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool CTcpmpPlayer::Prev(void)
|
|
{
|
|
if (m_Player)
|
|
{
|
|
if ((m_Player->Set(m_Player,PLAYER_PREV,NULL,0)) == ERR_NONE)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
}
|