⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediaplayer.c

📁 Brew SDK3.0 + vc2005 SDK3.0带的例子是VC2003下的例子
💻 C
📖 第 1 页 / 共 5 页
字号:
	else
		CMediaPlayer_RedrawNotify(pme);
}

/*===========================================================================
This function redraws the current window.
This function is called either by IShell in response to the resume scheduled
in CMediaPlayer_Redraw() or by CMediaPlayer_Redraw() directly.
===========================================================================*/
static void CMediaPlayer_RedrawNotify(CMediaPlayer * pme)
{
	if (!pme->m_bRedraw)
		return;

	pme->m_bRedraw = FALSE;

	if (pme->m_pWin)
	{
		IWINDOW_Enable(pme->m_pWin);
		IWINDOW_Redraw(pme->m_pWin);
	}
}

/*===========================================================================
This function opens the player window with the specified file.
It also tries to play the file if MediaPlayer is in plugin mode.

Note: This function allocates memory for the file name and the memory
is released by player window's destructor.
===========================================================================*/
static void CMediaPlayer_PlayFile(CMediaPlayer * pme, const char * pszFile)
{
	AEEMediaData   md;
	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 = STRDUP(pszFile);
	if (!pszBuf)
		return;

	// First check if this is image...
	if (CMediaPlayer_PlayImage(pme, pszBuf))
		return;

	// This is not image...it must be media.

	md.clsData = MMD_FILE_NAME;
	md.pData = (void *)pszBuf;
	md.dwSize = 0;

	if (!CMediaPlayer_SetWindow(pme, MPW_PLAYER, MPPW_PLAY))
	{
		FREE(pszBuf);
		return;
	}

	if (CPlayerWin_SetMediaData((CPlayerWin *)pme->m_pWin, &md))
	{
		ISHELL_PostEvent(pme->a.m_pIShell, AEECLSID_MEDIAPLAYER, EVT_CREATEMEDIA, 0, 0);
		if (pme->m_bPlugin)
			ISHELL_PostEvent(pme->a.m_pIShell, AEECLSID_MEDIAPLAYER, EVT_COMMAND, IDM_PM_PLAY, 0);
	}
}

/*===========================================================================
This function opens the record window with the specified file.
===========================================================================*/
static void CMediaPlayer_RecordQCPFile(CMediaPlayer * pme, const char * pszFile)
{
	AEEMediaData   md;
	char *         pszBuf;
	char sz[2] =   { DIRECTORY_CHAR, 0 };

	// 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 = MALLOC(MAX_FILE_NAME);
	if (!pszBuf)
		return;

	STRCPY(pszBuf, MP_MEDIA_DIR);
	STRCAT(pszBuf, sz);
	STRCAT(pszBuf, pszFile);
	md.clsData = MMD_FILE_NAME;
	md.pData = (void *)pszBuf;
	md.dwSize = 0;

	if (!CMediaPlayer_SetWindow(pme, MPW_PLAYER, (uint32)TRUE))
	{
		FREE(pszBuf);
		return;
	}

	if (CPlayerWin_SetMediaData((CPlayerWin *)pme->m_pWin, &md))
		ISHELL_PostEvent(pme->a.m_pIShell, AEECLSID_MEDIAPLAYER, EVT_CREATEMEDIA_QCP, 0, 0);
}

/*===========================================================================
This function displays the image in the player window.
===========================================================================*/
static boolean CMediaPlayer_PlayImage(CMediaPlayer * pme, const char * pszFile)
{
	IImage *       pImage = ISHELL_LoadImage(pme->a.m_pIShell, pszFile);
	CPlayerWin *   ppw;

	if (!pImage)
		return FALSE;

	if (!CMediaPlayer_SetWindow(pme, MPW_PLAYER, MPPW_IMAGE))
	{
		IIMAGE_Release(pImage);
		return FALSE;
	}

	ppw = (CPlayerWin *)pme->m_pWin;
	ppw->m_bImage = TRUE;      // This is an image
	ppw->m_bPlayRec = TRUE;    // It always plays
	ppw->m_pszFile = (char *)pszFile;  // Save the pointer

	if (ISHELL_CreateInstance(ppw->m_pIShell, AEECLSID_IMAGECTL, (void **)&ppw->m_pImageCtl))
		MP_ErrorDlg(ppw->m_pOwner, IDS_ERR_CREATEMEDIA);
	else
	{
		IIMAGECTL_SetRect(ppw->m_pImageCtl, &ppw->m_rectImage);
		IIMAGECTL_SetImage(ppw->m_pImageCtl, pImage);
		ppw->m_pImage = pImage;
		IIMAGE_Notify(pImage, CPlayerWin_ImageNotify, ppw);
		CMediaPlayer_Redraw(pme, TRUE);
	}

	return TRUE;
}

/*===========================================================================
This function returns the image/audio/default icon resource id if
extension is present in the internal list.
===========================================================================*/
static uint16 CMediaPlayer_IsExtension(CMediaPlayer * pme, const char * pszFile, char * pszInExt, int nExtLen)
{
	char *   psz;
	uint16   wRet = 0;
	char     szExt[10];

	psz = STRRCHR(pszFile, '.');
	if (!psz)
		return 0;

	psz++;
	if (!*psz)
		return 0;

	// Form a string like "mid, "
	STRCPY(szExt, psz);
	STRCAT(szExt, MP_EXT_SEPARATOR);

	if (pszInExt && nExtLen > (int)STRLEN(psz))
		STRCPY(pszInExt, psz);

	if (pme->m_pszAudioExt && STRSTR(pme->m_pszAudioExt, szExt))
		wRet = IDB_AUDIO_ICON;
	else if (pme->m_pszVideoExt && STRSTR(pme->m_pszVideoExt, szExt))
		wRet = IDB_VIDEO_ICON;
	else if (pme->m_pszImageExt && STRSTR(pme->m_pszImageExt, szExt))
		wRet = IDB_IMAGE_ICON;

	return wRet;
}

/*===========================================================================
This function tries to find the handler for an extension as follows:
(1) Search the internal lists for audio, video and image extensions
(2) If not found, then query Shell Registry for audio/video/image based handler
(3) If found, add the extension to internal list
===========================================================================*/
static uint16 CMediaPlayer_FindHandlerType(CMediaPlayer * pme, const char * pszFile)
{
	AEECLSID cls;
	char     szMIME[32];
	char     szExt[10] = {0,0,0,0};
	uint16   wExtType = CMediaPlayer_IsExtension(pme, pszFile, szExt, sizeof(szExt));

	if (wExtType)
		return wExtType;

	if (!STRCMP(szExt, ""))
		return 0;

	// Now query the Shell Registry...

	// Look for audio based handler
	STRCPY(szMIME, AUDIO_MIME_BASE);
	STRCAT(szMIME, szExt);
	cls = ISHELL_GetHandler(pme->a.m_pIShell, AEECLSID_MEDIA, szMIME);
	if (cls && MP_AddExtension(&pme->m_pszAudioExt, szExt))
		return IDB_AUDIO_ICON;

	// Look for video based handler
	STRCPY(szMIME, VIDEO_MIME_BASE);
	STRCAT(szMIME, szExt);
	cls = ISHELL_GetHandler(pme->a.m_pIShell, AEECLSID_MEDIA, szMIME);
	if (cls && MP_AddExtension(&pme->m_pszVideoExt, szExt))
		return IDB_VIDEO_ICON;

	// Look for image based handler
	STRCPY(szMIME, IMAGE_MIME_BASE);
	STRCAT(szMIME, szExt);
	cls = ISHELL_GetHandler(pme->a.m_pIShell, HTYPE_VIEWER, szMIME);
	if (cls && MP_AddExtension(&pme->m_pszImageExt, szExt))
		return IDB_IMAGE_ICON;

	return 0;
}

/*===============================================================================

CWindow Functions

=============================================================================== */
/*===========================================================================
This function is the base class constructor of an IWindow object.
It allocates memory for the interface and sets the vtbl.
===========================================================================*/
static IWindow * CWindow_New(int16 nSize, CMediaPlayer * pOwner, VTBL(IWindow) * pvt)
{
	CWindow *         pme;
	VTBL(IWindow)  *  pVtbl;

	pme = MALLOC(nSize + sizeof(VTBL(IWindow)));
	if (!pme)
		return NULL;

	pme->m_pOwner = pOwner;
	pme->m_pIShell = pme->m_pOwner->a.m_pIShell;
	pme->m_pIDisplay = pme->m_pOwner->a.m_pIDisplay;

	pVtbl = (VTBL(IWindow) *)((byte *)pme + nSize);
	MEMCPY(pVtbl, pvt, sizeof(VTBL(IWindow)));
	INIT_VTBL(pme, IWindow, *pVtbl);

	return (IWindow *)pme;
}

/*===========================================================================
This function indicates if IWINDOW_Enable()/IWINDOW_Disable() needs to be
processed and also sets the bActive flag appropriately.
It is called by derived class IWINDOW_Enable() function before processing
the command.
===========================================================================*/
static boolean CWindow_ProcessEnable(IWindow * po, boolean bEnable)
{
	CWindow *   pme = (CWindow *)po;
	boolean     bProc = TRUE;

	if (!bEnable)
	{
		if (pme->m_bActive)
		{
			pme->m_bActive = FALSE;
			CMediaPlayer_CancelRedraw(pme->m_pOwner);
		}
		else
			bProc = FALSE;
	}
	else
	{
		if (pme->m_bActive)
			bProc = FALSE;
		else
			pme->m_bActive = TRUE;
	}

	return bProc;
}

/*===============================================================================

CMainWin Functions

=============================================================================== */
/*===========================================================================
This function constucts the main window.
===========================================================================*/
static IWindow * CMainWin_New(CMediaPlayer * pOwner)
{
	CMainWin *        pme;
	VTBL(IWindow)     vtbl;

	MP_IWINDOW_SETVTBL(&vtbl, CMainWin_Enable, CMainWin_Redraw, CMainWin_HandleEvent, CMainWin_Delete);
	pme = (CMainWin *)CWindow_New(sizeof(CMainWin), pOwner, &vtbl);
	if (!pme)
		return NULL;

	{
		int      cx = pme->m_pOwner->m_cxWidth;
		int      cy = pme->m_pOwner->m_cyHeight;
		int      y, dy;
		AEERect  rect;

		// Initialize logo below the header
		pme->m_pLogo = ISHELL_LoadResImage(pme->m_pIShell, MEDIAPLAYER_RES_FILE, IDB_LOGO);
		if (!pme->m_pLogo)
			MP_WINERR_RETURN(pme);

		y = pme->m_pOwner->m_rectHdr.dy + 1;
		dy = cy/2 - y;
		SETAEERECT(&pme->m_rectLogo, 0, y, cx, dy);
		IIMAGE_SetFrameCount(pme->m_pLogo, 2);
		IIMAGE_SetAnimationRate(pme->m_pLogo, 500);

		if (ISHELL_CreateInstance(pme->m_pIShell, AEECLSID_MENUCTL, (void **)&pme->m_pMainMenu))
			MP_WINERR_RETURN(pme);

		SETAEERECT(&rect, 0, cy/2 + 1, cx, cy/2 - 1);
		MP_SetMenuAttr(pme->m_pMainMenu, AEECLSID_MENUCTL, pme->m_pOwner->m_nColorDepth, &rect, 0);
		MP_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_PLAYFILE, NULL, IDB_PLAY,     IDM_MAIN_PLAYFILE, 0);
		MP_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_RECORD,   NULL, IDB_RECORD,   IDM_MAIN_RECORD,   0);
#if defined(MEDIAPLAYER_SETTINGS)
		MP_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_SETTINGS, NULL, IDB_SETTINGS, IDM_MAIN_SETTINGS, 0);
#endif // defined(MEDIAPLAYER_SETTINGS)
		MP_AddMenuItem(pme->m_pMainMenu, IDM_MAIN_ABOUT,    NULL, IDB_ABOUT,    IDM_MAIN_ABOUT,    0);
	}

	return (IWindow *)pme;
}

/*===========================================================================
This function deletes the main window.
===========================================================================*/
static void CMainWin_Delete(IWindow * po)
{
	CMainWin *  pme = (CMainWin *)po;

	MP_RELEASEIF(pme->m_pLogo);

	if (pme->m_pMainMenu)
		pme->m_pOwner->m_wMainWin = IMENUCTL_GetSel(pme->m_pMainMenu);
	MP_RELEASEIF(pme->m_pMainMenu);

	FREE(pme);
}

/*===========================================================================
This function enables/disables the main window.
===========================================================================*/
static void CMainWin_Enable(IWindow * po, boolean bEnable)
{
	CMainWin *  pme = (CMainWin *)po;

	if (!CWindow_ProcessEnable(po, bEnable))
		return;

	if (!pme->m_bActive)
	{
		IMENUCTL_SetActive(pme->m_pMainMenu, FALSE);
		IIMAGE_Stop(pme->m_pLogo);
		return;
	}

	IMENUCTL_SetActive(pme->m_pMainMenu, TRUE);
	IMENUCTL_SetSel(pme->m_pMainMenu, pme->m_pOwner->m_wMainWin);
	MP_DrawImage(pme->m_pLogo, &pme->m_rectLogo, TRUE);
}

/*===========================================================================
This function redraws the main window.
===========================================================================*/
static void CMainWin_Redraw(IWindow * po)
{
	CMainWin *  pme = (CMainWin *)po;

	if (!pme->m_bActive)
		return;

	IDISPLAY_ClearScreen(pme->m_pIDisplay);

	MP_DRAWHEADER(pme);
	MP_DrawImage(pme->m_pLogo, &pme->m_rectLogo, TRUE);
	IMENUCTL_Redraw(pme->m_pMainMenu);

	IDISPLAY_Update(pme->m_pIDisplay);
}

/*===========================================================================
This function processes events routed to main window.
===========================================================================*/
static boolean CMainWin_HandleEvent(IWindow * po, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
	CMainWin *  pme = (CMainWin *)po;
	boolean     bRet = TRUE;

	if (eCode == EVT_COPYRIGHT_END && pme->m_bAbout)
	{
		pme->m_bAbout = FALSE;
		CMediaPlayer_Redraw(pme->m_pOwner, TRUE);
		return TRUE;
	}

	if (MP_ISEVTKEY(eCode))
		return IMENUCTL_HandleEvent(pme->m_pMainMenu, eCode, wParam, dwParam);

	if (!MP_ISEVTCMD(eCode))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -