402 lines
6.7 KiB
C++
402 lines
6.7 KiB
C++
|
#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)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
// <20><>ʼ<EFBFBD><CABC>TCPMP<4D><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
bool CTcpmpPlayer::Init(char* pVersion,int iVer,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);
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
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 Bool = 0;
|
|||
|
m_Player->Set(m_Player,PLAYER_FULLSCREEN,&Bool,sizeof(Bool));
|
|||
|
*/
|
|||
|
|
|||
|
//char pCharFile[]= "\\Storage Card\\1.mp3";
|
|||
|
|
|||
|
//static tchar_t FileName[MAX_PATH];
|
|||
|
//FormatTcpmpString(pCharFile,FileName);
|
|||
|
|
|||
|
//PlayerAdd(m_Player,0,FileName,NULL);
|
|||
|
//m_Player->Set(m_Player,PLAYER_STOP,NULL,0);
|
|||
|
/*Bool = 1;
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
m_Player->Set(m_Player,PLAYER_PLAY,&Bool,sizeof(Bool));
|
|||
|
}*/
|
|||
|
|
|||
|
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));
|
|||
|
|
|||
|
/*notify Notify;
|
|||
|
|
|||
|
Notify.This = m_Player;
|
|||
|
Notify.Func = (notifyfunc)PlayerNotify;
|
|||
|
m_Player->Set(m_Player,PLAYER_NOTIFY,&Notify,sizeof(Notify));*/
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void CTcpmpPlayer::SetDisplayRect(LPRECT lRect)
|
|||
|
{
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
m_Player->Set(m_Player,PLAYER_SKIN_VIEWPORT,lRect,sizeof(lRect));
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool CTcpmpPlayer::Play(bool bPause)
|
|||
|
{
|
|||
|
bool_t Bool;
|
|||
|
|
|||
|
if (bPause)
|
|||
|
{
|
|||
|
Bool = 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Bool = 0;
|
|||
|
}
|
|||
|
|
|||
|
if (m_Player && m_HasFile)
|
|||
|
{
|
|||
|
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 (!m_HasFile)
|
|||
|
{
|
|||
|
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(bMute)) == ERR_NONE)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
bool CTcpmpPlayer::GetMute(void)
|
|||
|
{
|
|||
|
bool bState;
|
|||
|
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
if(m_Player->Get(m_Player,PLAYER_MUTE,&bState,sizeof(bState)) == ERR_NONE)
|
|||
|
{
|
|||
|
return bState;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
int CTcpmpPlayer::SetCurrentPlayFile(char* pFileName)
|
|||
|
{
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
static tchar_t FileName[MAX_PATH];
|
|||
|
tchar_t ExtName[MAX_PATH];
|
|||
|
FormatTcpmpString("\\Storage Card",FileName);
|
|||
|
//FormatTcpmpString(pFileName,FileName);
|
|||
|
FormatTcpmpString("*.mp3",ExtName);
|
|||
|
|
|||
|
|
|||
|
//PlayerAdd(m_Player,0,FileName,NULL);
|
|||
|
int n = 0;
|
|||
|
n = PlayerAddDir(m_Player,n,FileName,ExtName,false,1);
|
|||
|
|
|||
|
//PlayerAdd(m_Player,0,FileName,NULL);
|
|||
|
//CString str;
|
|||
|
//str.Format(TEXT("Add %d Filse.\r\n"),n);
|
|||
|
//OutputDebugString(str);
|
|||
|
|
|||
|
m_Player->Set(m_Player,PLAYER_STOP,NULL,0);
|
|||
|
m_HasFile = TRUE;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
bool CTcpmpPlayer::HasPlayFile(void)
|
|||
|
{
|
|||
|
return m_HasFile;
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//int PlayerNotify(player* Player, int Id, int Value)
|
|||
|
//{
|
|||
|
//
|
|||
|
// CString str;
|
|||
|
// str.Format(TEXT("ID:%x,Value:%d\r\n"),Id,Value);
|
|||
|
// OutputDebugString(str);
|
|||
|
//
|
|||
|
// if (Id == PLAYER_EXIT_AT_END)
|
|||
|
// {
|
|||
|
// Player->Set(Player,PLAYER_STOP,NULL,0);
|
|||
|
// }
|
|||
|
// return 0;
|
|||
|
//}
|
|||
|
|
|||
|
player* CTcpmpPlayer::GetPlayerPtr(void)
|
|||
|
{
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
return m_Player;
|
|||
|
}
|
|||
|
|
|||
|
return NULL;
|
|||
|
}
|
|||
|
|
|||
|
void CTcpmpPlayer::SetPlayerNotify(LPVOID pWnd, long playerNotifyFunc)
|
|||
|
{
|
|||
|
notify Notify;
|
|||
|
|
|||
|
Notify.This = pWnd;
|
|||
|
Notify.Func = (notifyfunc)playerNotifyFunc;
|
|||
|
|
|||
|
m_Player->Set(m_Player,PLAYER_NOTIFY,&Notify,sizeof(Notify));
|
|||
|
}
|
|||
|
|
|||
|
bool CTcpmpPlayer::Next(void)
|
|||
|
{
|
|||
|
m_Player->Set(m_Player, PLAYER_NEXT, NULL, 1);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool CTcpmpPlayer::Prev(void)
|
|||
|
{
|
|||
|
m_Player->Set(m_Player, PLAYER_PREV, NULL, 1);
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
CString CTcpmpPlayer::GetPlayFileName(void)
|
|||
|
{
|
|||
|
CString str;
|
|||
|
|
|||
|
if (m_Player)
|
|||
|
{
|
|||
|
int i;
|
|||
|
m_Player->Get(m_Player,PLAYER_LIST_CURRENT,&i,sizeof(i));
|
|||
|
tchar_t name[MAX_PATH];
|
|||
|
|
|||
|
name[0] = 0;
|
|||
|
m_Player->Get(m_Player, PLAYER_LIST_URL, name, sizeof(name));
|
|||
|
|
|||
|
str = CString((TCHAR*)((unsigned short*)name));
|
|||
|
}
|
|||
|
|
|||
|
// MessageBox(str);
|
|||
|
OutputDebugString(str + TEXT("\r\n"));
|
|||
|
return str;
|
|||
|
}
|