📄 mediaplayer.c
字号:
if (!pme->m_bActive)
return;
if (MP_ISFULLSCRN(pme))
{
if (!pme->m_bPlayRec)
{
IDISPLAY_FillRect(pme->m_pIDisplay, NULL, RGB_BLACK);
IDISPLAY_Update(pme->m_pIDisplay);
}
else if (CPlayerWin_IsImage(pme))
{
IDISPLAY_ClearScreen(pme->m_pIDisplay);
IIMAGECTL_Redraw(pme->m_pImageCtl);
IDISPLAY_Update(pme->m_pIDisplay);
}
return;
}
IDISPLAY_ClearScreen(pme->m_pIDisplay);
// Header
MP_DRAWHEADER(pme);
// File name (title) text
if (pszFile)
{
STRTOWSTR(MP_GetFileName(pszFile), pme->m_szText, sizeof(pme->m_szText));
MP_FitStaticText(pme->m_pIDisplay, pme->m_pTitle, AEE_FONT_NORMAL, pme->m_szText);
ISTATIC_Redraw(pme->m_pTitle);
}
// Draw the line below text.
ISTATIC_GetRect(pme->m_pTitle, &rect);
rect.y += rect.dy - 1; rect.dy = 1;
MP_FrameRect(pme->m_pIDisplay, &rect);
// SoftKey
IMENUCTL_Redraw(pme->m_pPlayerMenu);
if (CPlayerWin_IsMedia(pme))
{
// Video/Image
if (!pme->m_bPlayRec)
MP_DrawImage(pme->m_pIdleImage, &pme->m_rectImage, TRUE);
// Progress bar...
CPlayerWin_UpdateProgCtl(pme, 0, 0, 0);
}
else if (CPlayerWin_IsImage(pme))
{
IIMAGECTL_Redraw(pme->m_pImageCtl);
IDISPLAY_Update(pme->m_pIDisplay);
}
}
/*===========================================================================
This function handles the events routed to the player window.
If the event is
(1) CLR or OK from error dialog:
(a) If app is in plugin mode, it is closed.
(b) If media playback is on, then file list window is opened
(c) If recording is on, then main window is opened
(2) AVK_0 or EVT_COMMAND(IDM_PM_FULLSCRN): Full screen is toggled
(3) EVT_CREATEMEDIA: Media is created using AEEMediaUtil_CreateMedia()
(4) EVT_CREATEMEDIA_QCP: IMediaQCP is created and its media data is set
to put it in Ready state.
(5) EVT_COMMAND: processes the menu commands.
(6) EVT_KEY: routed appropriately to the controls.
===========================================================================*/
static boolean CPlayerWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
CPlayerWin * pme = (CPlayerWin *)po;
boolean bRet = TRUE;
// Process CLR or OK from error dlg
if (MP_ISCLR(eCode) || MP_ISCMD(eCode, IDS_OK))
{
// Stop the app if it is in plugin mode.
if (MP_ISPLUGIN(pme))
ISHELL_CloseApplet(pme->m_pIShell, FALSE);
else
{
if (pme->m_eWin == MPPW_PLAY || pme->m_eWin == MPPW_IMAGE)
CMediaPlayer_SetWindow(pme->m_pOwner, MPW_FILELIST, 0);
else if (pme->m_eWin == MPPW_RECORD)
CMediaPlayer_SetWindow(pme->m_pOwner, MPW_MAIN, 0);
}
return TRUE;
}
// Process EVT_KEY...
if (MP_ISEVTKEY(eCode))
{
if (wParam == AVK_0)
CPlayerWin_FullScreen(pme, (boolean)!pme->m_bFullScreen, FALSE);
else if (CPlayerWin_IsMedia(pme))
return IMENUCTL_HandleEvent(pme->m_pPlayerMenu, eCode, wParam, dwParam);
else if (CPlayerWin_IsImage(pme))
{
if (wParam != AVK_SELECT)
return IIMAGECTL_HandleEvent(pme->m_pImageCtl, eCode, wParam, dwParam);
else
return IMENUCTL_HandleEvent(pme->m_pPlayerMenu, eCode, wParam, dwParam);
}
return TRUE;
}
// Process create media events...
if (eCode == EVT_CREATEMEDIA || eCode == EVT_CREATEMEDIA_QCP)
{
int nRet;
if (eCode == EVT_CREATEMEDIA)
nRet = AEEMediaUtil_CreateMedia(pme->m_pIShell, &pme->m_md, &pme->m_pMedia);
else
{
nRet = ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_MEDIAQCP, (void **)&pme->m_pMedia);
if (nRet == SUCCESS)
nRet = IMEDIA_SetMediaData(pme->m_pMedia, &pme->m_md);
}
if (SUCCESS != nRet)
MP_ErrorDlg(pme->m_pOwner, IDS_ERR_CREATEMEDIA);
else if (SUCCESS != IMEDIA_RegisterNotify(pme->m_pMedia, CPlayerWin_MediaNotify, pme))
MP_ErrorDlg(pme->m_pOwner, IDS_ERR_MEDIA);
else
{
uint32 dwCaps;
IMEDIA_GetMediaParm(pme->m_pMedia, MM_PARM_CAPS, (int32 *)&dwCaps, 0);
pme->m_bImage = (dwCaps & MM_CAPS_VIDEO) ? TRUE : FALSE;
if (!pme->m_bImage)
IMENUCTL_DeleteItem(pme->m_pPlayerMenu, IDM_PM_FULLSCRN);
else
IMEDIA_SetRect(pme->m_pMedia, &pme->m_rectImage, NULL);
CMediaPlayer_Redraw(pme->m_pOwner, TRUE);
}
return TRUE;
}
// If this event is not EVT_COMMAND, then return...
if (!MP_ISEVTCMD(eCode))
return FALSE;
if ( (CPlayerWin_IsMedia(pme) && !pme->m_pMedia) ||
(CPlayerWin_IsImage(pme) && !pme->m_pImageCtl) )
return TRUE;
// Process EVT_COMMAND...
switch (wParam)
{
case IDM_PM_PLAY:
if (CPlayerWin_IsPause(pme))
IMEDIA_Resume(pme->m_pMedia);
else if (SUCCESS != IMEDIA_GetTotalTime(pme->m_pMedia))
{
if (AEE_SUCCESS == IMEDIA_Play(pme->m_pMedia))
pme->m_bPlayRec = TRUE;
}
break;
case IDM_PM_RECORD:
if (CPlayerWin_IsPause(pme))
IMEDIA_Resume(pme->m_pMedia);
else if (AEE_SUCCESS == IMEDIA_Record(pme->m_pMedia))
pme->m_bPlayRec = TRUE;
break;
case IDM_PM_STOP:
IMEDIA_Stop(pme->m_pMedia);
break;
case IDM_PM_REWIND:
IMEDIA_Rewind(pme->m_pMedia, MP_SEEK_TIME);
break;
case IDM_PM_FF:
IMEDIA_FastForward(pme->m_pMedia, MP_SEEK_TIME);
break;
case IDM_PM_PAUSE:
if (CPlayerWin_IsPause(pme))
IMEDIA_Resume(pme->m_pMedia);
else
IMEDIA_Pause(pme->m_pMedia);
break;
case IDM_PM_UP:
{
uint16 wVol = pme->m_wVolume + MP_VOLUME_STEP;
wVol = (wVol > AEE_MAX_VOLUME) ? AEE_MAX_VOLUME : wVol;
IMEDIA_SetVolume(pme->m_pMedia, wVol);
break;
}
case IDM_PM_DOWN:
{
int16 nVol = (int16)pme->m_wVolume - MP_VOLUME_STEP;
nVol = (nVol < 0) ? 0 : nVol;
IMEDIA_SetVolume(pme->m_pMedia, (uint16)nVol);
break;
}
case IDM_PM_FULLSCRN:
CPlayerWin_FullScreen(pme, (boolean)!pme->m_bFullScreen, FALSE);
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
/*===========================================================================
This function indicates IMedia is in paused state.
===========================================================================*/
static boolean CPlayerWin_IsPause(CPlayerWin * pme)
{
boolean bChg;
int nState = IMEDIA_GetState(pme->m_pMedia, &bChg);
if (bChg)
return FALSE;
return (nState == MM_STATE_PLAY_PAUSE || nState == MM_STATE_RECORD_PAUSE);
}
/*===========================================================================
This function saves the file name and sets the media data locally.
Assumption: pmd is not NULL.
===========================================================================*/
static boolean CPlayerWin_SetMediaData(CPlayerWin * pme, AEEMediaData * pmd)
{
if (!pmd->pData)
return FALSE;
pme->m_pszFile = (char *)pmd->pData;
MEMCPY(&pme->m_md, pmd, sizeof(AEEMediaData));
return TRUE;
}
/*===========================================================================
This function toggles full screen mode and does a redraw.
===========================================================================*/
static boolean CPlayerWin_FullScreen(CPlayerWin * pme, boolean bFull, boolean bDeferRedraw)
{
if (!pme->m_bImage)
return FALSE;
if (!pme->m_bFullScreen)
{
SETAEERECT(&pme->m_rectImage, 0, 0, pme->m_pOwner->m_cxWidth, pme->m_pOwner->m_cyHeight);
}
else
{
MEMCPY(&pme->m_rectImage, &pme->m_rectImageCopy, sizeof(AEERect));
}
if (CPlayerWin_IsMedia(pme))
IMEDIA_SetRect(pme->m_pMedia, &pme->m_rectImage, NULL);
else if (CPlayerWin_IsImage(pme))
IIMAGECTL_SetRect(pme->m_pImageCtl, &pme->m_rectImage);
pme->m_bFullScreen = bFull;
CMediaPlayer_Redraw(pme->m_pOwner, bDeferRedraw);
return TRUE;
}
/*===============================================================================
ProgCtl Functions
=============================================================================== */
/*===========================================================================
This funtion initializes the ProgCtl.
ProgCtl contains two rectangles: main rectangle and within it the progress
bar rectangle. The title is displayed on left of the progress bar within
the main rectangle.
===========================================================================*/
static boolean CProgCtl_Init(CProgCtl * pme, AEERect * pRectMain)
{
AEERect rect;
int x, y;
int dxProg, dyProg;
MEMCPY(&pme->m_rectMain, pRectMain, sizeof(AEERect));
if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_STATIC, (void **)&pme->m_pTitle))
return FALSE;
// ProgBar rect
dxProg = pRectMain->dx / MP_PROGBAR_DX_DIV;
dyProg = pRectMain->dy / MP_PROGBAR_DY_DIV;
x = pRectMain->x + pRectMain->dx - dxProg + 1;
y = pRectMain->y + pRectMain->dy / 2 - dyProg/2;
if (dxProg > MP_PROGBAR_DX_OFFSET)
dxProg -= MP_PROGBAR_DX_OFFSET;
SETAEERECT(&pme->m_rectBar, x, y, dxProg, dyProg);
SETAEERECT(&rect, pRectMain->x + 1, pRectMain->y + 1, pRectMain->dx - dxProg, pRectMain->dy);
ISTATIC_SetRect(pme->m_pTitle, &rect);
ISTATIC_SetProperties(pme->m_pTitle, ST_CENTERTEXT | ST_NOSCROLL);
return TRUE;
}
/*===========================================================================
This function updates the progress bar and the title.
===========================================================================*/
static void CProgCtl_SetPos(CProgCtl * pme, AECHAR * psz, uint16 wPct)
{
MP_FitStaticText(pme->m_pIDisplay, pme->m_pTitle, AEE_FONT_NORMAL, psz);
ISTATIC_Redraw(pme->m_pTitle);
CProgCtl_DrawHist(pme, wPct);
MP_FrameRect(pme->m_pIDisplay, &pme->m_rectMain);
}
/*===========================================================================
This function deletes the ProgCtl
===========================================================================*/
static void CProgCtl_Release(CProgCtl * pme)
{
MP_RELEASEIF(pme->m_pTitle);
}
/*===========================================================================
This function fills wPct of progress bar rectangle.
===========================================================================*/
static void CProgCtl_DrawHist(CProgCtl * pme, uint16 wPct)
{
AEERect rc;
MEMCPY(&rc, &pme->m_rectBar, sizeof(AEERect));
if(wPct > 100)
wPct = 100;
IDISPLAY_DrawFrame(pme->m_pIDisplay, &rc, AEE_FT_RAISED, CLR_SYS_SCROLLBAR);
rc.dx = (rc.dx * wPct) / 100;
IDISPLAY_FillRect(pme->m_pIDisplay, &rc, MP_CLR_PROG_FILL);
}
/*===============================================================================
Local Functions
=============================================================================== */
/*===========================================================================
This function draws the image and centers it within the specified
rectangle if bCenter is TRUE.
===========================================================================*/
static void MP_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter)
{
AEEImageInfo ii;
int x;
int y;
IIMAGE_GetInfo(pImage, &ii);
// Do not display if image does not fit in the allocated rectangle.
if (ii.cx > pRect->dx || ii.cy > pRect->dy)
return;
if (bCenter)
{
x = pRect->x + (pRect->dx / 2) - (ii.cxFrame / 2);
y = pRect->y + (pRect->dy / 2) - (ii.cy / 2);
}
else
{
x = pRect->x;
y = pRect->y;
}
IIMAGE_Start(pImage, x, y);
}
/*===========================================================================
This function adds one item to the specified IMenuCtl.
===========================================================================*/
static boolean MP_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID, AECHAR * pText, uint16 wImageID, uint16 wItemID, uint32 dwData)
{
CtlAddItem ai;
// Fill in the CtlAddItem structure values
ai.pText = pText;
ai.pImage = NULL;
ai.pszResImage = MEDIAPLAYER_RES_FILE;
ai.pszResText = MEDIAPLAYER_RES_FILE;
ai.wText = wTextID;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -