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

📄 mymedia.c

📁 手机开发环境BREW实例
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: MyMedia.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEFile.h"			// File interface definitions
#include "AEEStdLib.h"        // AEE Stb Lib Services
#include "AEEMenu.h"          // AEE Menu Services
//#include "AEEImageCtl.h"      // AEE ImageCtl Services
#include "AEEDisp.h"
#include "AEEMedia.h"         // AEE Multimedia Services

#include "AEEMediaUtil.h"     // AEE Media Utility functions
#include "AEEMIMETypes.h"     // AEE MIME definitions

#include "MyMedia.bid"
#include "Media_res.h"
#include "MyMedia.h"

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
 
static boolean MyMedia_HandleEvent(IApplet * pi, AEEEvent eCode, 
                                      uint16 wParam, uint32 dwParam);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */

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

FUNCTION: AEEClsCreateInstance

DESCRIPTION
	This function is invoked while the app is being loaded. All Modules must provide this 
	function. Ensure to retain the same name and parameters for this function.
	In here, the module must verify the ClassID and then invoke the AEEApplet_New() function
	that has been provided in AEEAppGen.c. 

   After invoking AEEApplet_New(), this function can do app specific initialization. In this
   example, a generic structure is provided so that app developers need not change app specific
   initialization section every time except for a call to IDisplay_InitAppData(). 
   This is done as follows: InitAppData() is called to initialize AppletData 
   instance. It is app developers responsibility to fill-in app data initialization 
   code of InitAppData(). App developer is also responsible to release memory 
   allocated for data contained in AppletData -- this can be done in 
   IDisplay_FreeAppData().

PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)

PARAMETERS:
	clsID: [in]: Specifies the ClassID of the applet which is being loaded

	pIShell: [in]: Contains pointer to the IShell object. 

	pIModule: pin]: Contains pointer to the IModule object to the current module to which
	this app belongs

	ppObj: [out]: On return, *ppObj must point to a valid IApplet structure. Allocation
	of memory for this structure and initializing the base data members is done by AEEApplet_New().

DEPENDENCIES
  none

RETURN VALUE
  AEE_SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was
     successful
  EFAILED: If the app does not need to be loaded or if errors occurred in 
     AEEApplet_New(). If this function returns FALSE, the app will not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
   *ppObj = NULL;
		
   if(ClsId == AEECLSID_MYMEDIA){
      if(AEEApplet_New(sizeof(CPlayerWin), ClsId, pIShell,po,(IApplet**)ppObj,
         (AEEHANDLER)MyMedia_HandleEvent,(PFNFREEAPPDATA)AutoImage_FreeAppData)
         == TRUE)
      {
		 // Add your code here .....
		  if(AutoImage_InitAppData((IApplet *)*ppObj))
				return (AEE_SUCCESS);
			else
			{
				IAPPLET_Release((IApplet*)*ppObj);
				*ppObj = NULL;
				return EFAILED;
			}
      }
   }
	return (EFAILED);
}

static boolean AutoImage_InitAppData(IApplet* po)
{
	CPlayerWin * pme = (CPlayerWin *) po;
	int nAscent,nDescent;
	AEEDeviceInfo * pdi;
	AEERect  rectTitle;
	AEERect  rectProg;
	AEERect rectMenu;
//	IImage * pImage;
	int cx;
	int x,y;
	int dy;
	char * pszFile = "media/clap.qcp";//canyon.mid";

	//得到屏幕的相关信息
	pdi = MALLOC(sizeof(AEEDeviceInfo));
	if(!pdi)
		return FALSE;

	ISHELL_GetDeviceInfo(pme->a.m_pIShell,pdi);
	pme->m_cxWidth = pdi->cxScreen;
	pme->m_cyHeight = pdi->cyScreen;
	pme->m_nColorDepth = pdi->nColorDepth;
	FREEIF(pdi);

	IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay,AEE_FONT_LARGE,&nAscent,&nDescent);
	pme->m_nLChSize = nAscent + nDescent;

	IDISPLAY_GetFontMetrics(pme->a.m_pIDisplay,AEE_FONT_NORMAL,&nAscent,&nDescent);
	pme->m_nNChSize = nAscent + nDescent;

	cx = pme->m_cxWidth;
	dy = MP_HEADER_CY;
	x = 0;
	y = 0;	
	SETAEERECT(&pme->m_rectHdr,x,y,cx,dy);


	x = 0;
	y = pme->m_rectHdr.dy + 1;
	cx = pme->m_cxWidth;
   dy = pme->m_nLChSize;
   SETAEERECT(&rectTitle, x, y, cx, dy);

	ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_STATIC, (void **)&pme->m_pTitle);
	ISTATIC_SetRect(pme->m_pTitle, &rectTitle);
   ISTATIC_SetProperties(pme->m_pTitle, ST_CENTERTEXT | ST_NOSCROLL);

	pme->m_pIdleImage = ISHELL_LoadResImage(pme->a.m_pIShell,MEDIA_RES_FILE,IDB_GOOGLUCK);
	x = 0;
	y += rectTitle.dy + 1;
	cx = pme->m_cxWidth;
   dy = pme->m_cyHeight - y - MP_HEADER_CY - 12;
   SETAEERECT(&pme->m_pIdleRect, 0, y, cx, dy);

	pme->m_pszFile = pszFile;

   
      // ProgMain rect
   y += pme->m_pIdleRect.dy + 1;
	dy = 11;
   SETAEERECT(&rectProg, 0, y, cx, dy);

   // Initialize ProgCtl
   pme->m_ProgCtl.m_pIShell = pme->a.m_pIShell;
   pme->m_ProgCtl.m_pIDisplay = pme->a.m_pIDisplay;
   CProgCtl_Init(&pme->m_ProgCtl, &rectProg);
     

	y += dy + 1;
   dy = MP_HEADER_CY;
   SETAEERECT(&rectMenu, 0, y, cx, dy);


   ISHELL_CreateInstance(pme->a.m_pIShell, AEECLSID_SOFTKEYCTL, (void **)&pme->m_pPlayerMenu);

   MP_SetMenuAttr(pme->m_pPlayerMenu, AEECLSID_ICONVIEWCTL, pme->m_nColorDepth, &rectMenu, MP_MAXSOFTKEYITEMS);

	MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_PLAY,     IDM_PM_PLAY,   0);
   MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_STOP,     IDM_PM_STOP,   0);
   MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_REWIND,   IDM_PM_REWIND, 0);
   MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_PAUSE,    IDM_PM_PAUSE,  0);
   MP_AddMenuItem(pme->m_pPlayerMenu, 0, NULL, IDB_FF,       IDM_PM_FF,     0);
   MP_AddMenuItem(pme->m_pPlayerMenu,    0, NULL, IDB_UP,     IDM_PM_UP,     0);
   MP_AddMenuItem(pme->m_pPlayerMenu,    0, NULL, IDB_DOWN,   IDM_PM_DOWN,   0);

	CALLBACK_Init(&pme->m_cbRedraw,(PFNNOTIFY)AutoImage_RedrawNotify,pme);
	AutoImage_Redraw(pme, TRUE);
//	CMediaPlayer_Redraw(pme, TRUE);

	return TRUE;
}

static void AutoImage_FreeAppData(IApplet* po)
{
	CPlayerWin *   pme = (CPlayerWin *)po;
	AutoImage_CancelRedraw(pme);    
}

static void AutoImage_CancelRedraw(CPlayerWin * pme)
{

	FREEIF(pme->m_pszFile);
	MP_RELEASEIF(pme->m_pTitle);
	MP_RELEASEIF(pme->m_pMedia);
	MP_RELEASEIF((&pme->m_ProgCtl)->m_pTitle);
	MP_RELEASEIF(pme->m_pPlayerMenu);

	MP_RELEASEIF(pme->m_pIdleImage);

}
static void AutoImage_Redraw(CPlayerWin * pme, boolean bDefer)
{
   
   if (bDefer)
      ISHELL_Resume(pme->a.m_pIShell, &pme->m_cbRedraw);
   else
      AutoImage_RedrawNotify(pme);
}

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;
}

static void CMediaPlayer_PlayFile(CPlayerWin * 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;

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

   if (CPlayerWin_SetMediaData(pme, &md))
   {
      ISHELL_PostEvent(pme->a.m_pIShell, AEECLSID_MYMEDIA, EVT_CREATEMEDIA, 0, 0);
   }
}

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;
}

static void MP_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu, uint16 nColorDepth, AEERect * pRect, uint32 dwProps)
{
	AEEItemStyle		sel, normal;
	AEEMenuColors		col;

	// Menu Style
	normal.ft = AEE_FT_NONE;
	normal.xOffset = 0;
	normal.yOffset = 0;
	normal.roImage = AEE_RO_TRANSPARENT;

   sel.ft = AEE_FT_RAISED;
	sel.xOffset = 0;
	sel.yOffset = 0;
	sel.roImage = AEE_RO_TRANSPARENT;

	// Menu Colors
   col.cSelText = RGB_BLACK;
	col.wMask = (MC_BACK | MC_SEL_BACK | MC_SEL_TEXT);

   if (clsMenu == AEECLSID_MENUCTL)
   {
	   col.cBack = MAKE_RGB(255,255,204);
	   col.cSelBack = MAKE_RGB(153, 204, 204);

      dwProps |= IMENUCTL_GetProperties(pMenu);
   }
   else if (clsMenu == AEECLSID_SOFTKEYCTL || clsMenu == AEECLSID_ICONVIEWCTL)
   {
	   col.cBack = MAKE_RGB(192,192,192);
	   col.cSelBack = MAKE_RGB(192, 192, 192);

      dwProps |= MP_ICON_TEXT_TOP | MP_NO_ARROWS;
   }

   if (clsMenu == AEECLSID_MENUCTL || clsMenu == AEECLSID_SOFTKEYCTL || clsMenu == AEECLSID_ICONVIEWCTL)
   {
	   IMENUCTL_SetStyle(pMenu, &normal, &sel);
	   IMENUCTL_SetColors(pMenu, &col);
	   IMENUCTL_SetProperties(pMenu, dwProps);
      if (pRect)
         IMENUCTL_SetRect(pMenu, pRect);
   }
}

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 = MEDIA_RES_FILE;
   ai.pszResText = MEDIA_RES_FILE;
   ai.wText = wTextID;
   ai.wFont = AEE_FONT_NORMAL;
   ai.wImage = wImageID;
   ai.wItemID = wItemID;
   ai.dwData = dwData;

   // Add the item to the menu control
   return IMENUCTL_AddItemEx( pMenu, &ai );
}

static void AutoImage_RedrawNotify(CPlayerWin * pme)
{
      CPlayerWin_Enable(pme);
      CPlayerWin_Redraw(pme);
}

/////////////////////////////////////////////////////////////

static void CPlayerWin_Enable(CPlayerWin * po)
{
   CPlayerWin *   pme = po;

   ISTATIC_SetActive(pme->m_pTitle, TRUE);
   IMENUCTL_SetActive(pme->m_pPlayerMenu, TRUE);

   IMENUCTL_SetSel(pme->m_pPlayerMenu, (uint16)IDM_PM_PLAY );
}

static void CPlayerWin_Redraw(CPlayerWin * po)
{
   CPlayerWin *   pme = po;
   char *         pszFile = pme->m_pszFile;
   AEERect        rect;

   IDISPLAY_ClearScreen(pme->a.m_pIDisplay);


   // File name (title) text
   if (pszFile)
   {
      STRTOWSTR(MP_GetFileName(pszFile), pme->m_szText, sizeof(pme->m_szText));
      MP_FitStaticText(pme->a.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->a.m_pIDisplay, &rect);

   // SoftKey
   IMENUCTL_Redraw(pme->m_pPlayerMenu);

   MP_DrawImage(pme->m_pIdleImage, &pme->m_pIdleRect, TRUE);

      // Progress bar...
   CPlayerWin_UpdateProgCtl(pme, 0, 0, 0);

}

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)

⌨️ 快捷键说明

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