?? media.cpp
字號:
// Media.cpp: implementation of the CMedia class.
//
//////////////////////////////////////////////////////////////////////
#include "Media.h"
#include "wk_basefunc.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMedia::CMedia()
{
m_pApplet = NULL;
m_bMyDoc = FALSE;
}
CMedia::~CMedia()
{
}
void CMedia::Create()
{
// 傳送項目列表信息
long nLength, nBufferLength;
long nIndex;
long nValue;
long nTotal, nChunk1, nChunk2;
char szPrefix[] = {'W', 'X', 'F', 'Z', '\0'};
m_bRelease = FALSE;
if(m_bMyDoc)
{
ReadDoc();
return;
}
// APPID + VERSION + SZMOBILE + SZMOBILETYPE + REQUESTTYPE
// 計算發送請求的總長度
nBufferLength = 0;
nLength = STRLEN(szPrefix); // prifix
nBufferLength += sizeof(char) * (nLength);
nBufferLength += 4; // APPID
nBufferLength += 4; // VERSION
nBufferLength += 4; // TotalSize
nBufferLength += 4; // Number of Chunks
nBufferLength += 4; // REQUESTTYPE
nBufferLength += 4; // Size
nChunk1 = nBufferLength;
nLength = WSTRLEN(m_szMobile) + 1; // SZMOBILE
nBufferLength += sizeof(AECHAR) * (nLength);
nLength = WSTRLEN(m_szMobileType) + 1; // SZMOBILETYPE
nBufferLength += sizeof(AECHAR) * (nLength);
nBufferLength += 4;
nChunk1 = nBufferLength - nChunk1;
nBufferLength += 4; // REQUESTTYPE
nBufferLength += 4; // Size
nChunk2 = nBufferLength;
nBufferLength += 4; // CategoryID
nChunk2 = nBufferLength - nChunk2;
nTotal = nBufferLength;
if (m_szPostData)
FREEIF(m_szPostData);
m_szPostData = (char *) MALLOC(nBufferLength);
nIndex = 0;
// Prefix
nLength = sizeof(char) * (STRLEN(szPrefix));
MEMCPY(m_szPostData + nIndex, szPrefix, nLength);
// APPID
nIndex += nLength;
nLength = 4;
nValue = APPID;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// VERSION
nIndex += nLength;
nLength = 4;
nValue = VERSION;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Total size
nIndex += nLength;
nLength = sizeof(long);
nLength = 4;
nValue = nTotal;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// number of chunks
nIndex += nLength;
nLength = 4;
nValue = 2;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk type
nIndex += nLength;
nLength = 4;
nValue = REQUEST_ACCOUNT;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk size
nIndex += nLength;
nLength = 4;
nValue = nChunk1;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// MOBILE
nIndex += nLength;
nLength = sizeof(AECHAR) * (WSTRLEN(m_szMobile) + 1);
MEMCPY(m_szPostData + nIndex, m_szMobile, nLength);
// MOBILETYPE
nIndex += nLength;
nLength = sizeof(AECHAR) * (WSTRLEN(m_szMobileType) + 1);
MEMCPY(m_szPostData + nIndex, m_szMobileType, nLength);
//login
nIndex += nLength;
nLength = 4;
if(m_pNetWork->m_bFirst)
nValue=1;
else
nValue=0;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk type
nIndex += nLength;
nLength = 4;
nValue = REQUEST_CONTENT;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// Chunk size
nIndex += nLength;
nLength = 4;
nValue = nChunk2;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// contentid
nIndex += nLength;
nLength = 4;
nValue = m_nID;
MEMCPY(m_szPostData + nIndex, &nValue, nLength);
// 發送請求信息
m_pNetWork->PostData(m_szPostData, nBufferLength, (CObject *)this);
}
void CMedia::PlayFile(const char * pszFile)
{
// char * pszBuf;
// File name is a special case...
// pszFile will be released by CFileListWin when CPlayerWin opens.
// Allocate memory for file name here. It will be used and released
// by CPlayerWin.
// pszBuf = (char*)STRDUP(pszFile);
m_nState=STATE_CONTENT;
// if (!pszBuf)
// return;
// First check if this is image...
if ((m_nType & 0xffff) == CONTENT_PIC)
{
PlayImage(pszFile);
}
else
{
if(!m_bResum)
{
m_md.clsData = MMD_FILE_NAME;
m_md.pData = (void *)pszFile;
m_md.dwSize = 0;
ISHELL_PostEvent(m_pApplet->m_pIShell, CLASS_ID, EVT_CREATEMEDIA, 0, 0);
}
ShowMedia();
}
}
boolean CMedia::PlayImage(const char * pszFile)
{
if(!m_bResum)
{
ReleaseMenu();
ReleaseMedia();
ReleaseProgCtl();
ClearScreen();
}
else
{
if(m_pImage)
{
AEEImageInfo info;
int xPos,yPos;
IIMAGE_GetInfo(m_pImage,&info);
xPos = (m_pDevice->cxScreen-info.cx)/2;
yPos = (m_pDevice->cyScreen-info.cy)/2;
IDISPLAY_ClearScreen(m_pApplet->m_pIDisplay);
IIMAGE_Start(m_pImage,xPos,yPos);
IDISPLAY_Update(m_pApplet->m_pIDisplay);
return TRUE;
}
}
IImage * pImage = ISHELL_LoadImage(m_pApplet->m_pIShell, pszFile);
AEEImageInfo info;
int xPos,yPos;
if (!pImage)
return FALSE;
IIMAGE_GetInfo(pImage,&info);
xPos = (m_pDevice->cxScreen-info.cx)/2;
yPos = (m_pDevice->cyScreen-info.cy)/2;
IDISPLAY_ClearScreen(m_pApplet->m_pIDisplay);
if((m_nType & 0xffff0000)==PIC_BCI)
{
m_pImage=pImage;
IIMAGE_Start(m_pImage,xPos,yPos);
}
else
{
IIMAGE_Draw(pImage,xPos,yPos);
IIMAGE_Release(pImage);
}
IDISPLAY_Update(m_pApplet->m_pIDisplay);
return TRUE;
}
void CMedia::Init(AECHAR *szName, long nID, XFRAMEINFO *pInfo)
{
int i;
m_nID = nID;
if (szName)
{
long nLen = sizeof(AECHAR) * (WSTRLEN(szName) + 1);
m_szName = (AECHAR *)MALLOC(nLen);
MEMCPY(m_szName, szName, nLen);
}
else
m_szName = NULL;
m_szFileName = NULL;
m_pApplet = pInfo->pApplet;
m_pDevice = pInfo->pDevice;
m_pNetWork = (CNetWork *)pInfo->pNetWork;
m_szMobile = pInfo->szMobile;
m_szMobileType = pInfo->szMobileType;
m_pIStatic = NULL;
m_szReceiveData = NULL;
m_szPostData = NULL;
m_nBufferLength = 0;
m_pFileMgr = NULL;
m_pObject = NULL;
m_bRelease = TRUE;
m_bImage = FALSE;
m_bPlayRec = FALSE;
m_bPlayResume = TRUE;
m_nState = STATE_OPTION;
m_bResum = FALSE;
m_pMenu = NULL;
m_pImage = NULL;
m_nMenuSelect = 0;
m_nButtonIndex = BUTTON_PLAY;
m_nButtonCount = 5;
i = 0;
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_1);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_SEL1);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_2);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_SEL2);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_3);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_SEL3);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_4);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_SEL4);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_5);
m_icon[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_PLAYICON_SEL5);
i = 0;
m_imgMusic[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_MUSIC1);
m_imgMusic[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_MUSIC2);
m_imgMusic[i++] = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_MUSIC3);
// m_imgBack = ISHELL_LoadResImage(m_pApplet->m_pIShell, RES_FILE, BM_BACK);
}
void CMedia::Construct(char *szBuffer, long nBufferLength)
{
long nIndex;
long cstLong;
long nPostType, nValue;
char szExt[10];
IDISPLAY_ClearScreen(m_pApplet->m_pIDisplay);
if ((nBufferLength <= 0) || (szBuffer == NULL))
return;
// read head info
nIndex = 0;
cstLong = 4;
// prifix
nIndex = 4;
// total size
MEMCPY(&nValue, szBuffer + nIndex, 4);
nIndex += 4;
// post type
MEMCPY(&nPostType, szBuffer + nIndex, 4);
nIndex += 4;
// number of Chunks
MEMCPY(&nValue, szBuffer + nIndex, 4);
nIndex += 4;
// chunkID
MEMCPY(&nValue, szBuffer + nIndex, 4);
nIndex += 4;
// chunkSize
MEMCPY(&nValue, szBuffer + nIndex, 4);
nIndex += 4;
// read text from buffer and add menu item
if (nPostType == REQUEST_CONTENT)
{// 圖片、鈴聲
// read nContentID
MEMCPY(&nValue, szBuffer + nIndex, cstLong);
nIndex += cstLong;
// read nSize
MEMCPY(&nValue, szBuffer + nIndex, cstLong);
nIndex += cstLong;
if (nValue > nBufferLength - nIndex)
nValue = nBufferLength - nIndex;
// 保存文件內容
if (m_szReceiveData) FREEIF(m_szReceiveData);
m_nBufferLength = nValue + sizeof(AECHAR);
m_szReceiveData = (char *) MALLOC(m_nBufferLength);
MEMCPY(m_szReceiveData, szBuffer + nIndex, nValue);
MEMSET(m_szReceiveData + nValue, 0, sizeof(AECHAR));
if(m_pFileMgr)
{
IFILEMGR_Release(m_pFileMgr);
m_pFileMgr = NULL;
}
if (!CheckFileSpace(m_pApplet->m_pIShell))
{
AEERect rcScreen;
rcScreen.x=0;
rcScreen.y=0;
rcScreen.dx=m_pDevice->cxScreen;
rcScreen.dy=m_pDevice->cyScreen;
ClearScreen();
ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &rcScreen, m_szName, IDS_ERR_SPACE);
m_nState=STATE_ERRO;
}
else if(GetExt(szExt))
{
FREEIF(m_szFileName);
m_szFileName = (char*)MALLOC(9);
SPRINTF(m_szFileName, "temp%s", szExt);
if(SaveFile(m_pApplet->m_pIShell,&m_pFileMgr,m_szFileName,m_szReceiveData,m_szFileName,m_nBufferLength))
{
m_nState = STATE_OPTION;
Display();
}
else
{
ClearScreen();
AEERect rcScreen;
rcScreen.x=0;
rcScreen.y=0;
rcScreen.dx=m_pDevice->cxScreen;
rcScreen.dy=m_pDevice->cyScreen;
ShowResString(m_pApplet->m_pIShell, &m_pIStatic, &rcScreen, m_szName, IDS_ERR_SPACE);
m_nState=STATE_ERRO;
}
}
else
{
//erro
}
//釋放
if (m_szReceiveData) FREEIF(m_szReceiveData);
if(m_pFileMgr)
{
IFILEMGR_Release(m_pFileMgr);
m_pFileMgr = NULL;
}
}
return;
}
void CMedia::Release()
{
ClearScreen();
ReleaseMenu();
ReleaseMedia();
ReleaseProgCtl();
CleanRingerPtr();
if (m_szName) FREEIF(m_szName);
if (m_szReceiveData) FREEIF(m_szReceiveData);
if (m_szPostData) FREEIF(m_szPostData);
if(m_szFileName) FREEIF(m_szFileName);
if (m_pObject)
{
m_pObject->Release();
delete m_pObject;
m_pObject = NULL;
}
if(m_pFileMgr)
{
IFILEMGR_Release(m_pFileMgr);
m_pFileMgr = NULL;
}
if(m_pImage)
{
IIMAGE_Stop(m_pImage);
IIMAGE_Release(m_pImage);
m_pImage=NULL;
}
// 釋放圖片
{
int i = 0;
for (i = 0; i < 10; i++)
{
if(m_icon[i])
IIMAGE_Release(m_icon[i]);
m_icon[i] = NULL;
}
for (i = 0; i < 3; i++)
{
if(m_imgMusic[i])
IIMAGE_Release(m_imgMusic[i]);
m_imgMusic[i] = NULL;
}
/*
if(m_imgBack)
IIMAGE_Release(m_imgBack);
m_imgBack = NULL;
*/
}
m_bRelease = TRUE;
}
void CMedia::ClearScreen()
{
if(m_pIStatic)
ReleaseObj((void * *)&m_pIStatic);
m_pIStatic = NULL;
}
boolean CMedia::GetExt(char *szExt)
{
switch(m_nType & 0xffff0000)
{
case SOUND_MID:
STRCPY(szExt, ".mid");
break;
case SOUND_MMF:
STRCPY(szExt, ".mmf");
break;
case SOUND_PMD:
STRCPY(szExt, ".pmd");
break;
case SOUND_MP3:
STRCPY(szExt, ".mp3");
break;
case SOUND_QCP:
STRCPY(szExt, ".qcp");
break;
case SOUND_WAV:
STRCPY(szExt, ".wav");
break;
case PIC_PNG:
STRCPY(szExt, ".png");
break;
case PIC_BMP:
STRCPY(szExt, ".bmp");
break;
case PIC_GIF:
STRCPY(szExt, ".gif");
break;
case PIC_JPG:
STRCPY(szExt, ".jpg");
break;
case PIC_BCI:
STRCPY(szExt, ".bci");
break;
default:
return FALSE;
}
return TRUE;
}
boolean CMedia::KeyHandle(AEEEvent evt, uint16 wParam, uint32 dwParam)
{
boolean status = FALSE;
switch(evt)
{
//Key handler
case EVT_KEY:
//case EVT_KEY_PRESS:
if (wParam == AVK_CLR)
{
if(m_nState==STATE_OPTION)
{
// PreView();
if(!m_bMyDoc)
{
DeleteFile(m_pApplet->m_pIShell,&m_pFileMgr,m_szFileName);
}
Release();
}
else if(m_nState==STATE_CONTENT)
{
ReleaseMedia();
if(m_pImage)
{
IIMAGE_Stop(m_pImage);
IIMAGE_Release(m_pImage);
m_pImage=NULL;
}
ShowOption(m_nType&0xffff);
}
else if(m_nState==STATE_ERRO)
Release();
status = TRUE;
}
else if (m_nState==STATE_CONTENT)
{
switch (wParam)
{
case AVK_RIGHT:
case AVK_DOWN:
if(m_nButtonIndex >= m_nButtonCount - 1)
m_nButtonIndex = 0;
else
m_nButtonIndex++;
break;
case AVK_LEFT:
case AVK_UP:
if(m_nButtonIndex <= 0)
m_nButtonIndex = m_nButtonCount - 1;
else
m_nButtonIndex--;
break;
case AVK_SELECT:
{
if (HIDE_MUSIC_BUTTON)
return TRUE;
if (m_nButtonIndex == BUTTON_PLAY)
{// play
if(m_pMedia)
{
if (IsPause())
IMEDIA_Resume(m_pMedia);
else if (m_bPlayRec == FALSE)
{// 播放時不能再按play鍵
int nRet;
nRet = IMEDIA_GetTotalTime(m_pMedia);
nRet = IMEDIA_Play(m_pMedia);
if (AEE_SUCCESS == nRet)
m_bPlayRec = TRUE;
}
}
}
else if (m_nButtonIndex == BUTTON_STOP)
{// stop
if(m_pMedia)
IMEDIA_Stop(m_pMedia);
}
else if (m_nButtonIndex == BUTTON_REWIND)
{// rewind
if(m_pMedia)
IMEDIA_Rewind(m_pMedia, TIME_INMILLISECONDS);
}
else if (m_nButtonIndex == BUTTON_FF)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -