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

📄 mediaplayer.c

📁 BREW SDK 3.1。BREW应用程序的开发包。
💻 C
📖 第 1 页 / 共 5 页
字号:

int         CMediaPlayer_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj);
static int  CMediaPlayer_Load(IShell *ps, void * pHelpers, IModule ** pMod);

//
// Constant Data...
//
static const AEEAppInfo    gaiMediaPlayerApp = {AEECLSID_MEDIAPLAYER,MEDIAPLAYER_RES_FILE,IDS_TITLE,IDB_TNAIL,IDB_TNAIL,0,0,0};

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

                      PUBLIC FUNCTION DECLARATIONS

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

//===========================================================================
//
// 
//
//===========================================================================
PFNMODENTRY CMediaPlayer_GetModInfo(IShell * ps, AEECLSID ** ppClasses, AEEAppInfo ** pApps, uint16 * pnApps,uint16 * pwMinPriv)
{
   *pApps = (AEEAppInfo *)&gaiMediaPlayerApp;
   *pnApps = 1;
   return((PFNMODENTRY)CMediaPlayer_Load);
}

//===========================================================================
//
//===========================================================================
static int CMediaPlayer_Load(IShell *ps, void * pHelpers, IModule ** pMod)
{
   return(AEEStaticMod_New((int16)(sizeof(AEEMod)),ps,pHelpers,pMod,CMediaPlayer_CreateInstance,NULL));
}

#endif  //AEE_STATIC

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

Function:  CMediaPlayer_InitAppData()

Description:
		This function initializes the app specific data.

Prototype:
	void CMediaPlayer_InitAppData(IApplet* po)

Parameters:
   IApplet* po: Pointer to the applet structure. This is of the type defined
	to store applet data. (CMediaPlayer*, in this case).

Return Value:
	TRUE: If successful
	FALSE: IF failed

Comments:  None

Side Effects: None

==============================================================================*/
boolean CMediaPlayer_InitAppData(IApplet* po)
{
	CMediaPlayer *    pme = (CMediaPlayer*)po;
   int               nAscent, nDescent;
   AEEDeviceInfo *   pdi;

   // Get screen pixel count
   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;

   pme->m_pHdrImage = ISHELL_LoadResImage(pme->a.m_pIShell, MEDIAPLAYER_RES_FILE, IDB_HEADER);
   if (!pme->m_pHdrImage)
      return FALSE;
   SETAEERECT(&pme->m_rectHdr, 0, 0, pme->m_cxWidth, MP_HEADER_CY);

   CALLBACK_Init(&pme->m_cbRedraw, (PFNNOTIFY)CMediaPlayer_RedrawNotify, pme);

   pme->m_pWin = CMainWin_New(pme);
   if (!pme->m_pWin)
      return FALSE;

   return TRUE;
}

/*===========================================================================
Function:  CMediaPlayer_FreeAppData()

Description:
	This function frees the app data. This function is registered with the
	applet framework when the applet is created (inside AEEClsCreateInstance() function).
	This function is called by the app framework when the reference count of the 
	applet reaches zero. This function must free all the app data that has been
	allocated by this app. For ex: if their is data that was remembered when
	the app is suspended and resumed, those data must be freed here.

Prototype:
	void CMediaPlayer_FreeAppData(IApplet* po)

Parameters:
   IApplet* po: Pointer to the applet structure. This is of the type defined
	to store applet data. (CMediaPlayer*, in this case).

Return Value:
	None

Comments:  None

Side Effects: None
==============================================================================*/
void CMediaPlayer_FreeAppData(IApplet* po)
{
	CMediaPlayer * pme = (CMediaPlayer *)po;

   MP_RELEASEIF(pme->m_pHdrImage);
   
   CMediaPlayer_CancelRedraw(pme);
   MP_RELEASEWIN(pme->m_pWin);

   FREEIF(pme->m_pszAudioExt);
   FREEIF(pme->m_pszVideoExt);
   FREEIF(pme->m_pszImageExt);
}

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

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.

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 interface. 

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

	ppObj: [out]: On return, *ppApplet must point to a valid IBase object. 
	If the classID	represnts an applet, then ppObj must point to a valid AEEApplet 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 class/app creation was successful. 
  EFAILED: Error occurred while creating the class/app. In this case, the app/class will
  not be loaded.

SIDE EFFECTS
  none
===========================================================================*/
#if defined(AEE_STATIC)
int CMediaPlayer_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#else
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#endif
{
	*ppObj = NULL;

   //
   // Here a check is done to see if the ClsID is that of MediaPlayer app.
   // The reason is if this module has more than one applets or classes, then this function is invoked
   // once for each applet or class. Checking here ensures that the correct IApplet or class object is
   // constructed.
   //
   if(ClsId == AEECLSID_MEDIAPLAYER)
	{
		//Create the applet
      if(AEEApplet_New(sizeof(CMediaPlayer), ClsId, pIShell,po,(IApplet**)ppObj,(AEEHANDLER)CMediaPlayer_HandleEvent,(PFNFREEAPPDATA)CMediaPlayer_FreeAppData))
		{
			//Initialize applet data
         if(CMediaPlayer_InitAppData((IApplet*)*ppObj))
			{
				//Data initialized successfully
				return(AEE_SUCCESS);
			}
			else
			{
				//Release the applet. This will free the memory allocated for the applet when
				*ppObj = NULL;
				IAPPLET_Release((IApplet*)*ppObj);
				return EFAILED;
			}

      }//AEEApplet_New

   }// ClsId == AEECLSID_MEDIAPLAYER

   return(EFAILED);
}

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

FUNCTION CMediaPlayer_HandleEvent

DESCRIPTION
	This is the EventHandler for this app. All events to this app are handled in this
	function. All APPs must supply an Event Handler.

PROTOTYPE:
	boolean CMediaPlayer_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)

PARAMETERS:
	pi: Pointer to the AEEApplet structure. This structure contains information specific
	to this applet. It was initialized during the AppClsCreateInstance() function.

	ecode: Specifies the Event sent to this applet

   wParam, dwParam: Event specific data.

DEPENDENCIES
  none

RETURN VALUE
  TRUE: If the app has processed the event
  FALSE: If the app did not process the event

SIDE EFFECTS
  none
===========================================================================*/
static boolean CMediaPlayer_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
    CMediaPlayer * pme = (CMediaPlayer *)pi;

    switch ( eCode ) 
    {   
         case EVT_APP_START:   // Process Start event
         {
            //
            // An app can be started from app manager or from another app with arguments. 
            // dwParam contains the string argument passed to the applet when it is started.
            // In case of MediaPlayer app, if the argument is present, then it means that
            // the applet is started as a plugin with argument specifying file name of the
            // media. In this case, the player window is directly invoked and the media
            // starts playing immediately.
            //
            AEEAppStart * pas = (AEEAppStart *)dwParam;
            if (pas->pszArgs)
            {
               pme->m_bPlugin = TRUE;
               CMediaPlayer_PlayFile(pme, pas->pszArgs);
            }
            else
               CMediaPlayer_DrawSplash(pme);

            return TRUE;
         }

         case EVT_APP_BROWSE_FILE:
         {
            //
            // This event is sent when ISHELL_BrowseFile() API finds
            // MediaPlayer app as the registered handler. Shell first
            // sends EVT_APP_START followed by this event. The dwParam
            // contains the file name.
            // Start the MediaPlayer app in plugin mode.
            //
            if (dwParam)
            {
               char *   psz = (char *)dwParam;
               CMediaPlayer_SetWindow(pme, MPW_NONE, NULL);
               pme->m_bPlugin = TRUE;
               CMediaPlayer_PlayFile(pme, psz);
            }
            return TRUE;
         }

         case EVT_APP_STOP:        // process STOP event
            return (TRUE);

         case EVT_APP_SUSPEND:
            //
            // If playback ia going on, then stop the playback and close the window. This ensures that
            // all the multimedia resources allocated for playback are released. 
            // On resume, open file list window.
            //
            pme->m_eSuspendWin = pme->m_eActiveWin == MPW_PLAYER ? MPW_FILELIST : pme->m_eActiveWin;
            CMediaPlayer_SetWindow(pme, MPW_NONE, 0);
            return (TRUE);

         case EVT_APP_RESUME:
            CMediaPlayer_SetWindow(pme, pme->m_eSuspendWin, 0);
            return (TRUE);

         case EVT_KEY:	            // Process key event
         case EVT_COMMAND:          // Process menu command event
         case EVT_CREATEMEDIA:      // Create media
         case EVT_CREATEMEDIA_QCP:  // Create IMediaQCP for recoring
         case EVT_COPYRIGHT_END:    // Copyright dialog ended
            if (pme->m_pWin)
               return IWINDOW_HandleEvent(pme->m_pWin, eCode, wParam, dwParam);

    }

    return FALSE;
}

/*===========================================================================
   This function draws the splash screen and brings up the main window
   after the splash timer runs out.
===========================================================================*/
static void CMediaPlayer_DrawSplash(CMediaPlayer * pme)
{
   // The following 'If statement' is entered only after the splash timer runs out...
   if (pme->m_eActiveWin == MPW_MAIN)
   {
      CMediaPlayer_SetWindow(pme, MPW_MAIN, 0);
      return;
   }

   // Draw the splash screen, set the timer.
   // The timer callback calls this function and redraws the main window.
   {
      IImage * pi = ISHELL_LoadResImage(pme->a.m_pIShell, MEDIAPLAYER_RES_FILE, IDB_LOGO);

      if (pi)
      {
         AEERect  rect;

         IDISPLAY_ClearScreen(pme->a.m_pIDisplay);
         SETAEERECT(&rect, 0, 0, pme->m_cxWidth, pme->m_cyHeight);
         MP_DrawImage(pi, &rect, TRUE);
         IDISPLAY_Update(pme->a.m_pIDisplay);
         MP_RELEASEIF(pi);
      }

      // Set main window as active and start the timer.
      pme->m_eActiveWin = MPW_MAIN;
      ISHELL_SetTimer(pme->a.m_pIShell, MP_SPLASH_TIMER, (PFNNOTIFY)CMediaPlayer_DrawSplash, pme);
   }  
}

/*===========================================================================
   This function switches from one window to another:
   (1) Releases all the resources associated with the current window
   (2) Contructs the new window, if any
   (3) Enables and redraws the new window, if any
===========================================================================*/
static boolean CMediaPlayer_SetWindow(CMediaPlayer * pme, MPWindow eWin, uint32 dwParam)
{
   // If same window, then redraw and return.
   if (pme->m_pWin && pme->m_eActiveWin == eWin && eWin != MPW_NONE)
   {
      CMediaPlayer_Redraw(pme, TRUE);
      return TRUE;
   }

   MP_RELEASEWIN(pme->m_pWin);

   switch (eWin)
   {
      case MPW_MAIN:       
         pme->m_pWin = CMainWin_New(pme); 
         break;

      case MPW_FILELIST:   
         pme->m_pWin = CFileListWin_New(pme); 

⌨️ 快捷键说明

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