Mediaplayer.c
上传用户:hejie16899
上传日期:2021-10-21
资源大小:4758k
文件大小:31k
- /*===========================================================================
- FILE: MediaPlayer.c
- ===========================================================================*/
- /*===============================================================================
- INCLUDES AND VARIABLE DEFINITIONS
- =============================================================================== */
- #include "AEEModGen.h" // Module interface definitions
- #include "AEEAppGen.h" // Applet interface definitions
- #include "AEEShell.h" // Shell interface definitions
- #include "AEEStdLib.h"
- #include "AEEFile.h" // File interface definitions
- #include "AEEMedia.h"
- //include of me
- #include "mediaplayer.h"
- #include "MediaPlayer.bid"
- #include "res.brh"
- /*-------------------------------------------------------------------
- /*-------------------------------------------------------------------
- DEFINITIONS
- -------------------------------------------------------------------*/
- #define MP_LOGO_TIMER 2000 //开机logo暂停时间,2 seconds
- #define MP_ICONVIEWCTL_CY 20
- #define MP_VOLUME_STEP 25 //音量控制
- #define MP_SEEK_TIME 10000 //播放时快 进/退时间 10 seconds
- #define MP_PROGBAR_DX_DIV 3 // dx is dx/3 of main rectangle
- #define MP_PROGBAR_DY_DIV 2 // dy is dy/2 of main rectangle
- #define MP_PROGBAR_DX_OFFSET 4 // dx is reduced by offset
- #define MENU8_FT AEE_FT_NONE //边框类型,没有边框
- #define MENU8_SELECT_FT AEE_FT_RAISED //凸起的 2 像素三维边框
- //特定颜色的 SRC 像素是透明的意味着可看穿相应的 DST 像素
- #define MENU8_RO AEE_RO_TRANSPARENT
- #define MENU8_SELECT_RO AEE_RO_TRANSPARENT
- //掩码集 指示需要更改其颜色的项目
- #define MENU8_COLOR_MASK (MC_BACK | MC_SEL_BACK | MC_SEL_TEXT)
- //设置显示颜色
- #define MENU8_BACKGROUND MAKE_RGB(255, 255, 204)
- #define MENU8_SELECT_BACKGROUND MAKE_RGB(153, 204, 204)
- #define MENU8_SELECT_TEXT RGB_BLACK
- #define MP_CLR_PROG_FILL MAKE_RGB(0, 128, 192)
- #define TB8_BACKGROUND MAKE_RGB(192,192,192)
- #define TB8_SELECT_BACKGROUND MAKE_RGB(192, 192, 192)
- #define MP_MEDIA_DIR "media" //保存歌曲目录
- #define MP_RELEASEIF(p) MP_FreeIF((IBase **)&(p)) //释放接口指针,并赋值NULL
- /*-------------------------------------------------------------------
- Function Prototypes
- -------------------------------------------------------------------*/
- static boolean MediaPlayer_HandleEvent(MediaPlayer* pMe, AEEEvent eCode,
- uint16 wParam, uint32 dwParam);
- boolean MediaPlayer_InitAppData(MediaPlayer* pMe);
- void MediaPlayer_FreeAppData(MediaPlayer* pMe);
- /*===============================================================================
- FUNCTION DEFINITIONS
- =============================================================================== */
- static void MediaPlayer_DrawLogo (MediaPlayer* pMe); //画开机LOGO
- static boolean MediaPlayer_SetWindow(MediaPlayer * pMe, CMPWindow eWin);//设置界面切换接口
- static void MediaPlayer_DrawMain (MediaPlayer* pMe); //系统开始主界面
- static void MediaPlayer_DrawSongList (MediaPlayer* pMe); //歌曲列表界面
- static void MediaPlayer_DrawSongPlay (MediaPlayer* pMe); //歌曲播放界面
- //获取图片信息并判断是否居中显示
- static void MP_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter);
- static void MP_PlaySong (MediaPlayer* pMe); //播放歌曲
- static void MP_FreeIF(IBase ** ppif); //释放接口指针并负责NULL
- static void MP_LoadFileToList(MediaPlayer *pMe); //枚举目录歌曲列表
- static boolean MP_AddMenuItem(IMenuCtl * pMenu, uint16 wTextID,
- AECHAR * pText, uint16 wImageID,
- uint16 wItemID, uint32 dwData); //设置菜单项
- static char * MP_GetFileName(const char * psz); //取出文件名字,去掉目录
- static void MP_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu,
- uint16 nColorDepth, AEERect * pRect,
- uint32 dwProps);
- static void MP_MediaNotify(void * pUser, AEEMediaCmdNotify * pCmdNotify);//media回调事情处理
- static void MP_UpdateProgCtl(MediaPlayer * pme, int nCmd, int nSubCmd, uint16 wResID);
- static void MP_FitStaticText(IDisplay * pd, IStatic * ps, AEEFont font, AECHAR * pszText);
- static void MP_FrameRect(IDisplay * pd, AEERect * pRect);
- static boolean MP_IsPause(MediaPlayer * pMe);
- static boolean CProgCtl_Init(MediaPlayer * pme, AEERect * pRectMain);
- static void CProgCtl_SetPos(MediaPlayer * pme, AECHAR * psz, uint16 wPct);
- static void CProgCtl_DrawHist(MediaPlayer * pme, uint16 wPct);
- /*===========================================================================
- FUNCTION: AEEClsCreateInstance
- ===========================================================================*/
- int AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void **ppObj)
- {
- *ppObj = NULL;
- if( ClsId == AEECLSID_MEDIAPLAYER )
- {
- // Create the applet and make room for the applet structure
- if( AEEApplet_New(sizeof(MediaPlayer),
- ClsId,
- pIShell,
- po,
- (IApplet**)ppObj,
- (AEEHANDLER)MediaPlayer_HandleEvent,
- (PFNFREEAPPDATA)MediaPlayer_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
-
- {
- //Initialize applet data, this is called before sending EVT_APP_START
- // to the HandleEvent function
- if(MediaPlayer_InitAppData((MediaPlayer*)*ppObj))
- {
- //Data initialized successfully
- return(AEE_SUCCESS);
- }
- else
- {
- //Release the applet. This will free the memory allocated for the applet when
- // AEEApplet_New was called.
- IAPPLET_Release((IApplet*)*ppObj);
- return EFAILED;
- }
- } // end AEEApplet_New
- }
- return(EFAILED);
- }
- /*===========================================================================
- FUNCTION SampleAppWizard_HandleEvent
- ===========================================================================*/
- static boolean MediaPlayer_HandleEvent(MediaPlayer* pApp, AEEEvent eCode,
- uint16 wParam, uint32 dwParam)
- {
-
- if (pApp->m_pMainMenu && IMENUCTL_HandleEvent(pApp->m_pMainMenu, eCode, wParam, dwParam))
- {
- return TRUE;
- }
- if (pApp->m_pFileMenu && IMENUCTL_HandleEvent(pApp->m_pFileMenu, eCode, wParam, dwParam))
- {
- pApp->m_item=IMENUCTL_GetSel(pApp->m_pFileMenu);
- return TRUE;
- }
-
- if (pApp->m_pPlayerMenu && IMENUCTL_HandleEvent(pApp->m_pPlayerMenu, eCode, wParam, dwParam))
- {
- return TRUE;
- }
- switch (eCode)
- {
- // App is told it is starting up
- case EVT_APP_START:
- MediaPlayer_DrawLogo(pApp); //画开机LOGO
- return(TRUE);
- // App is told it is exiting
- case EVT_APP_STOP:
- // Add your code here...
- return(TRUE);
-
- case EVT_APP_SUSPEND:
- // Add your code here...
- return(TRUE);
- // App is being resumed
- case EVT_APP_RESUME:
- // Add your code here...
- return(TRUE);
-
- case EVT_APP_MESSAGE:
- // Add your code here...
- return(TRUE);
-
- case EVT_KEY:
- //在歌曲列表界面并按了CLR键,退回到主界面,如果media_play,歌曲不停止
- if ((pApp->m_eActiveWin==MPW_SONGLIST))
- {
- if (wParam == AVK_RIGHT && pApp->m_pIMedia)
- {
-
- MediaPlayer_SetWindow(pApp,MPW_SONGPLAYER);
- }
- if (wParam == AVK_LEFT || wParam == AVK_CLR)
- {
- IMENUCTL_SetActive( pApp->m_pFileMenu, FALSE );
- IMENUCTL_Redraw(pApp->m_pFileMenu);
- MediaPlayer_SetWindow(pApp,MPW_MAIN);
- }
- }
- // Add your code here..
- if (pApp->m_eActiveWin == MPW_SONGPLAYER)
- {
- if (wParam == AVK_CLR)
- {
- IMENUCTL_SetActive( pApp->m_pPlayerMenu, FALSE );
- IMENUCTL_Redraw(pApp->m_pPlayerMenu);
- MediaPlayer_SetWindow(pApp,MPW_SONGLIST);
- }
- }
- return(TRUE);
-
- case EVT_COMMAND:
- if (pApp->m_item == wParam)
- {
- if (pApp->m_pIMedia)
- {
- IMEDIA_Stop(pApp->m_pIMedia);
- }
- MediaPlayer_SetWindow(pApp,MPW_SONGPLAYER);
- MP_PlaySong(pApp);
- }
- switch(wParam)
- {
- case IDS_SONGLIST:
- MediaPlayer_SetWindow(pApp,MPW_SONGLIST);
- break;
- case IDM_PM_PLAY:
- if (MP_IsPause(pApp))
- {
- IMEDIA_Resume(pApp->m_pIMedia);
- }
- else if (SUCCESS != IMEDIA_GetTotalTime(pApp->m_pIMedia))
- {
- if (AEE_SUCCESS == IMEDIA_Play(pApp->m_pIMedia))
- {
- pApp->m_bPlayRec = TRUE;
- }
- }
- break;
-
- case IDM_PM_STOP:
- IMEDIA_Stop(pApp->m_pIMedia);
- break;
- case IDM_PM_BACK:
- pApp->m_item--;
- IMEDIA_Stop(pApp->m_pIMedia);
- if (pApp->m_item < IDM_FILELIST_BASE)
- {
- pApp->m_item = pApp->m_MaxSongFile;
- }
- MediaPlayer_SetWindow(pApp,MPW_SONGPLAYER);
- MP_PlaySong(pApp);
- break;
-
- case IDM_PM_REWIND:
- IMEDIA_Rewind(pApp->m_pIMedia, MP_SEEK_TIME);
- break;
-
- case IDM_PM_FF:
- IMEDIA_FastForward(pApp->m_pIMedia, MP_SEEK_TIME);
- break;
-
- case IDM_PM_PAUSE:
- if (MP_IsPause(pApp))
- IMEDIA_Resume(pApp->m_pIMedia);
- else
- IMEDIA_Pause(pApp->m_pIMedia);
- break;
- case IDM_PM_NEXT:
- pApp->m_item++;
- IMEDIA_Stop(pApp->m_pIMedia);
- if (pApp->m_item > pApp->m_MaxSongFile)
- {
- pApp->m_item = IDM_FILELIST_BASE;
- }
- MediaPlayer_SetWindow(pApp,MPW_SONGPLAYER);
- MP_PlaySong(pApp);
- break;
- case IDM_PM_UP:
- {
-
- uint16 wVol = pApp->m_wVolume + MP_VOLUME_STEP;
- wVol = (wVol > AEE_MAX_VOLUME) ? AEE_MAX_VOLUME : wVol;
- IMEDIA_SetVolume(pApp->m_pIMedia, wVol);
- break;
- }
-
- case IDM_PM_DOWN:
- {
- int16 nVol = (int16)pApp->m_wVolume - MP_VOLUME_STEP;
- nVol = (nVol < 0) ? 0 : nVol;
- IMEDIA_SetVolume(pApp->m_pIMedia, (uint16)nVol);
- break;
- }
- default:
- break;
- }
-
- default:
- break;
- }
-
- return FALSE;
- }
- // this function is called when your application is starting up
- boolean MediaPlayer_InitAppData(MediaPlayer* pApp)
- {
- // Get the device information for this handset.
- // Reference all the data by looking at the pMe->DeviceInfo structure
- // Check the API reference guide for all the handy device info you can get
- pApp->DeviceInfo.wStructSize = sizeof(pApp->DeviceInfo);
- ISHELL_GetDeviceInfo(pApp->a.m_pIShell,&pApp->DeviceInfo);
- pApp->m_cxWidth = pApp->DeviceInfo.cxScreen;
- pApp->m_cyHeight = pApp ->DeviceInfo.cyScreen;
- pApp->m_nColorDepth = pApp->DeviceInfo.nColorDepth;
- return TRUE;
- }
- // this function is called when your application is exiting
- void MediaPlayer_FreeAppData(MediaPlayer* pMe)
- {
- int i;
- MP_RELEASEIF(pMe->m_pIMedia);
- MP_RELEASEIF(pMe->m_pTitle);
- MP_RELEASEIF(pMe->m_pFileMenu);
- MP_RELEASEIF(pMe->m_pPlayerMenu);
- MP_RELEASEIF(pMe->m_pSOFTKEYMenu);
- MP_RELEASEIF(pMe->m_pMainMenu);
-
- for (i = 0; i < pMe->m_NumFiles; i++ )
- {
- if (pMe->m_szFileArray[i])
- FREE((void *)pMe->m_szFileArray[i]);
- }
- }
- //画开机LOGO
- static void MediaPlayer_DrawLogo(MediaPlayer* pApp)
- {
- //判断界面标记m_eActiveWin是否激活主界面
- if (pApp->m_eActiveWin == MPW_MAIN)
- {
- MediaPlayer_SetWindow(pApp, MPW_MAIN); //进入界面选择,播放器开始主界面
- return;
- }
-
- {
- //装载资源编辑器logo图片
- IImage *pi = ISHELL_LoadResImage(pApp->a.m_pIShell, RES_RES_FILE,IDI_LOGO);
-
- //转载成功就进行绘制,失败则释放IImage 指针并赋值NULL
- if (pi)
- {
- AEERect rect;
- IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
- SETAEERECT(&rect, 0, 0, pApp->m_cxWidth,pApp->m_cyHeight);
- MP_DrawImage(pi, &rect, TRUE);
- IDISPLAY_Update(pApp->a.m_pIDisplay);
- MP_RELEASEIF(pi);
- }
- else
- {
- MP_RELEASEIF(pi);
- }
-
- pApp->m_eActiveWin = MPW_MAIN; //激活主界面标记m_eActiveWin = MPW_MAIN
-
- //计时器,LOGO停留MP_lOGO_TIMER时间,重新调用MediaPlayer_DrawLogo
- ISHELL_SetTimer(pApp->a.m_pIShell, MP_LOGO_TIMER, (PFNNOTIFY)MediaPlayer_DrawLogo, pApp);
- }
- }
- //根据m_eActiveWin标记来选择界面
- static boolean MediaPlayer_SetWindow(MediaPlayer * pApp, CMPWindow eWin)
- {
- DBGPRINTF("CMediaPlay_SetWindow");
- switch (eWin)
- {
- case MPW_MAIN:
- MediaPlayer_DrawMain(pApp); //播放器开始主界面
- break;
-
- case MPW_SONGLIST:
- MediaPlayer_DrawSongList(pApp); //歌曲列表界面
- break;
-
- case MPW_SONGPLAYER:
- MediaPlayer_DrawSongPlay(pApp); //歌曲播放界面
- break;
-
- default:
- return FALSE;
- break;
- }
- return TRUE;
- }
- //系统开始主界面
- static void MediaPlayer_DrawMain (MediaPlayer* pApp)
- {
- AEERect rect;
- AEERect rRect;
- IImage *pi = ISHELL_LoadResImage(pApp->a.m_pIShell, RES_RES_FILE, IDI_MAINLOGO);
-
- if (!pi)
- {
- MP_RELEASEIF(pApp);
- MP_RELEASEIF(pi);
- return;
- }
- pApp->m_eActiveWin = MPW_MAIN;
- IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
- if (ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_MENUCTL, (void **)&pApp->m_pMainMenu))
- {
- MP_RELEASEIF(pApp);
- return;
- }
-
- SETAEERECT(&rect, 0, 0, pApp->m_cxWidth,pApp->m_cyHeight/2);
- SETAEERECT(&rRect, 0, pApp->m_cyHeight/2, pApp->m_cxWidth,pApp->m_cyHeight/2);
- MP_DrawImage(pi, &rect, TRUE);
- IDISPLAY_Update(pApp->a.m_pIDisplay);
- MP_RELEASEIF(pi);
-
- //设置菜单
- IMENUCTL_AddItem(pApp->m_pMainMenu,RES_RES_FILE, IDS_SONGLIST,IDS_SONGLIST, NULL, 0 );
- IMENUCTL_AddItem(pApp->m_pMainMenu,RES_RES_FILE, IDS_ABOUT,IDS_ABOUT, NULL, 0 );
- IMENUCTL_SetRect( pApp->m_pMainMenu, &rRect ); //设置菜单位置
- IMENUCTL_SetActive( pApp->m_pMainMenu, TRUE ); //激活主菜单控件
- }
- //歌曲列表界面
- static void MediaPlayer_DrawSongList (MediaPlayer* pApp)
- {
- IImage * pHeader;
- AEERect rect;
- pApp->m_eActiveWin = MPW_SONGLIST; //设置歌曲列表界面标记
- DBGPRINTF("CMediaPlay_DrawSongList");
- IMENUCTL_SetActive( pApp->m_pMainMenu, FALSE); //主菜单控件
- IMENUCTL_Redraw(pApp->m_pMainMenu);
- IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
- pHeader = ISHELL_LoadResImage(pApp->a.m_pIShell,RES_RES_FILE,IDI_HEADER);
-
- if (!pHeader)
- {
- MP_RELEASEIF(pHeader);
- }
-
- SETAEERECT(&rect,0,0,pApp->m_cxWidth, pApp->m_cyHeight/7);
- MP_DrawImage(pHeader, &rect, TRUE);
- IDISPLAY_Update(pApp->a.m_pIDisplay);
- MP_RELEASEIF(pHeader);
- MP_LoadFileToList(pApp);//装入歌曲菜单
- }
- //歌曲播放界面
- static void MediaPlayer_DrawSongPlay (MediaPlayer* pApp)
- {
- AEERect rect;
- AEERect rectMenu;
- AEERect rectProg;
- IImage *pi;
- IImage *pHeader;
- pi = ISHELL_LoadResImage(pApp->a.m_pIShell, RES_RES_FILE, IDI_MAINLOGO);
- if (!pi)
- {
- MP_RELEASEIF(pi);
- }
-
- pHeader = ISHELL_LoadResImage(pApp->a.m_pIShell,RES_RES_FILE,IDI_HEADER);
- if (!pHeader)
- {
- MP_RELEASEIF(pHeader);
- }
- pApp->m_eActiveWin = MPW_SONGPLAYER;
- IMENUCTL_SetActive( pApp->m_pFileMenu, FALSE); //主菜单控件失效
- IMENUCTL_Redraw(pApp->m_pFileMenu);
- IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
- {
- SETAEERECT(&rect,0,0,pApp->m_cxWidth, pApp->m_cyHeight/7);
- MP_DrawImage(pHeader, &rect, TRUE);
- }
- {
- SETAEERECT(&rect, 0, pApp->m_cyHeight/7, pApp->m_cxWidth,pApp->m_cyHeight/2);
- MP_DrawImage(pi, &rect, TRUE);
- }
-
- IDISPLAY_Update(pApp->a.m_pIDisplay);
- MP_RELEASEIF(pHeader);
- MP_RELEASEIF(pi);
- {
-
- int cx = pApp->m_cxWidth;
- int cy = pApp->m_cyHeight;
- int y = cy - MP_ICONVIEWCTL_CY;
- int dy = MP_ICONVIEWCTL_CY;
- SETAEERECT(&rectMenu, 0, y, cx, dy);
-
- ISHELL_CreateInstance(pApp->a.m_pIShell,AEECLSID_SOFTKEYCTL,
- (void**)(&pApp->m_pPlayerMenu));
-
- SETAEERECT(&rectProg,
- 0,
- pApp->m_cyHeight-pApp->m_cyHeight/7,
- pApp->m_cxWidth,
- pApp->m_cyHeight/5-pApp->m_cyHeight/7);
-
- if (!CProgCtl_Init(pApp, &rectProg))
- {
- }
- MP_SetMenuAttr(pApp->m_pPlayerMenu,
- AEECLSID_ICONVIEWCTL,
- pApp->m_nColorDepth,
- &rectMenu,
- MP_MAXSOFTKEYITEMS);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_PLAY, IDM_PM_PLAY, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_PAUSE, IDM_PM_PAUSE, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_STOP, IDM_PM_STOP, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_BAKE, IDM_PM_BACK, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_REWIND, IDM_PM_REWIND, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_FASTFORWARD, IDM_PM_FF, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_NEXT, IDM_PM_NEXT, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_UP, IDM_PM_UP, 0);
- MP_AddMenuItem(pApp->m_pPlayerMenu, 0, NULL, IDI_DOWN, IDM_PM_DOWN, 0);
- IMENUCTL_SetRect( pApp->m_pPlayerMenu, &rectMenu );
- IMENUCTL_SetActive( pApp->m_pPlayerMenu, TRUE );
- }
- }
- //播放歌曲
- static void MP_PlaySong(MediaPlayer* pApp)
- {
- AEEMediaData pmd;
- char * pszBuf;
-
- if(SUCCESS != ISHELL_CreateInstance(pApp->a.m_pIShell,
- AEECLSID_MEDIAMP3,
- (void **)&pApp->m_pIMedia))
- {
- MP_RELEASEIF(pApp->m_pIMedia);
- }
-
- pszBuf = pApp->m_szFileArray[pApp->m_item - IDM_FILELIST_BASE];
- if (!pszBuf)
- {
- return;
- }
-
- pmd.clsData = MMD_FILE_NAME;
- pmd.pData = pszBuf;
- pmd.dwSize = 0;
- IMEDIA_SetMediaData (pApp->m_pIMedia, &pmd);
- IMEDIA_GetTotalTime(pApp->m_pIMedia);
- IMEDIA_Play(pApp->m_pIMedia);
-
- if (SUCCESS == IMEDIA_RegisterNotify(pApp->m_pIMedia, MP_MediaNotify ,pApp))
- {
- }
-
-
- }
- //获取图片信息并判断是否居中显示
- static void MP_DrawImage(IImage * pImage, AEERect * pRect, boolean bCenter)
- {
- AEEImageInfo ii;
- int x;
- int y;
-
- DBGPRINTF("MP_DrawImage");
- 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);
- }
- //释放接口指针并负责NULL
- static void MP_FreeIF(IBase ** ppif)
- {
- if (ppif && *ppif)
- {
- IBASE_Release(*ppif);
- *ppif = NULL;
- }
- }
- //装在歌曲文件到播放列表
- static void MP_LoadFileToList(MediaPlayer *pApp)
- {
- IFileMgr* pIFileMgr;
- uint16 wItemID = 0;
- AECHAR* pzBuf;
- // char* pszBuf;
- AEERect rect;
-
- SETAEERECT(&rect,
- 0,
- pApp->m_cyHeight/7,
- pApp->m_cxWidth,
- pApp->m_cyHeight-pApp->m_cyHeight/7);
-
- pzBuf = MALLOC(MAX_FILE_NAME * sizeof(AECHAR));
- if(!pzBuf)
- {
- MP_RELEASEIF(pApp);
- return ;
- }
-
- if (ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_MENUCTL, (void **)&pApp->m_pFileMenu))
- {
- MP_RELEASEIF(pApp);
- }
-
- if ( ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_FILEMGR, (void **)&pIFileMgr) != SUCCESS )
- {
- MP_RELEASEIF(pApp);
- return ;
- }
-
- IFILEMGR_EnumInit(pIFileMgr, MP_MEDIA_DIR, FALSE);
-
- while (wItemID < CMP_MAX_FILES && IFILEMGR_EnumNext(pIFileMgr, &pApp->m_pFileInfo))
- {
- char * szName;
-
- //pApp->m_szFileArray[wItemID] = STRDUP(pApp->m_pFileInfo.szName);
- pApp->m_szFileArray[wItemID] = (char*)MALLOC(STRLEN(pApp->m_pFileInfo.szName) + 1);
- MEMSET(pApp->m_szFileArray[wItemID], 0, STRLEN(pApp->m_pFileInfo.szName) + 1);
- STRCPY(pApp->m_szFileArray[wItemID], pApp->m_pFileInfo.szName);
- if (!pApp->m_szFileArray[wItemID])
- {
- pApp->m_NumFiles = wItemID;
- FREE(pzBuf);
- MP_RELEASEIF(pIFileMgr);
- }
-
- szName = MP_GetFileName(pApp->m_pFileInfo.szName);
-
- if (szName)
- {
- STRTOWSTR(szName, pzBuf, MAX_FILE_NAME);
- MP_AddMenuItem(pApp->m_pFileMenu,
- 0,
- pzBuf,
- IDI_IMAGE2,
- (uint16)(IDM_FILELIST_BASE + wItemID),
- 0);
- }
-
- wItemID++;
-
- }
- pApp->m_MaxSongFile = IDM_FILELIST_BASE+wItemID-1;
- pApp->m_NumFiles = wItemID;
- IMENUCTL_SetRect( pApp->m_pFileMenu, &rect );
- IMENUCTL_SetActive( pApp->m_pFileMenu, TRUE );
- IMENUCTL_Redraw(pApp->m_pFileMenu);
- MP_RELEASEIF(pIFileMgr);
- FREE(pzBuf);
- }
- 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 = RES_RES_FILE;
- ai.pszResText = RES_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 char * MP_GetFileName(const char * psz)
- {
- char * pszName = STRRCHR(psz, (int)DIRECTORY_CHAR);
-
- if (pszName)
- {
- pszName++;
- }
- else
- {
- pszName = (char *)psz;
- }
- return pszName;
- }
- static void MP_SetMenuAttr(IMenuCtl * pMenu, AEECLSID clsMenu, uint16 nColorDepth,
- AEERect * pRect, uint32 dwProps)
- {
- AEEItemStyle sel, normal;
- AEEMenuColors col;
-
- // Menu Style
- normal.ft = MENU8_FT;
- normal.xOffset = 0;
- normal.yOffset = 0;
- normal.roImage = MENU8_RO;
-
- sel.ft = MENU8_SELECT_FT;
- sel.xOffset = 0;
- sel.yOffset = 0;
- sel.roImage = MENU8_SELECT_RO;
-
- // Menu Colors
- col.cSelText = MENU8_SELECT_TEXT;
- col.wMask = MENU8_COLOR_MASK;
-
- if (clsMenu == AEECLSID_MENUCTL)
- {
- col.cBack = MENU8_BACKGROUND;
- col.cSelBack = MENU8_SELECT_BACKGROUND;
- dwProps |= IMENUCTL_GetProperties(pMenu);
- }
- else if (clsMenu == AEECLSID_SOFTKEYCTL || clsMenu == AEECLSID_ICONVIEWCTL)
- {
- col.cBack = TB8_BACKGROUND;
- col.cSelBack = TB8_SELECT_BACKGROUND;
-
- 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 void MP_MediaNotify(void * pUser, AEEMediaCmdNotify * pCmdNotify)
- {
- uint16 nTextID = 0;
- MediaPlayer* pMe=(MediaPlayer *)pUser;
-
- switch (pCmdNotify->nStatus)
- {
- case MM_STATUS_SEEK_FAIL:
- case MM_STATUS_PAUSE_FAIL:
- case MM_STATUS_RESUME_FAIL:
- nTextID = IDS_ERR_PLAYCTL_CMD;
- break;
- }
-
- if (pCmdNotify->nCmd == MM_CMD_PLAY ) // IMEDIA_Play/IMEDIA_Record events
- {
- nTextID = IDS_PLAY ;
- switch (pCmdNotify->nStatus)
- {
- case MM_STATUS_START:
- IMENUCTL_SetSel(pMe->m_pPlayerMenu, IDM_PM_STOP);
- break;
-
- case MM_STATUS_MEDIA_SPEC:
- break;
-
- case MM_STATUS_TICK_UPDATE: // Typcally, one-second update
- pMe->m_dwPlayPos++;
-
- if (!pMe->m_dwTotalTime) // If no total time increase by 20!
- {
- pMe->m_wPct = (pMe->m_wPct + 20) % 100;
- }
- break;
-
- case MM_STATUS_SEEK:
- nTextID = IDS_SEEK;
-
- if (pCmdNotify->dwSize)
- {
- pMe->m_dwPlayPos = (uint32)pCmdNotify->pCmdData / 1000;
- }
- break;
-
- case MM_STATUS_PAUSE:
- nTextID = IDS_PAUSE;
- if (pCmdNotify->dwSize)
- {
- pMe->m_dwPlayPos = (uint32)pCmdNotify->pCmdData / 1000;
- }
-
- break;
-
- case MM_STATUS_RESUME:
-
- if (pCmdNotify->dwSize)
- {
- pMe->m_dwPlayPos = (uint32)pCmdNotify->pCmdData / 1000;
- }
-
- break;
-
- case MM_STATUS_DONE: // playback done
- case MM_STATUS_ABORT: // playback aborted
- {
- nTextID = (pCmdNotify->nStatus == MM_STATUS_DONE) ? IDS_STOP : IDS_ABORT;
- pMe->m_bPlayRec = FALSE;
- pMe->m_dwPlayPos = 0;
- pMe->m_wPct = 0;
- IMENUCTL_SetSel(pMe->m_pPlayerMenu, IDM_PM_PLAY);
- break;
- }
- }
-
- if (pMe->m_eActiveWin == MPW_SONGPLAYER)
- {
- MP_UpdateProgCtl(pMe, pCmdNotify->nCmd, pCmdNotify->nSubCmd, nTextID);
- }
-
- } // MM_CMD_PLAY
- else if (pCmdNotify->nCmd == MM_CMD_GETTOTALTIME)
- {
- if (pCmdNotify->nStatus == MM_STATUS_DONE || pCmdNotify->nStatus == MM_STATUS_ABORT)
- {
- pMe->m_dwTotalTime = ((uint32)pCmdNotify->pCmdData) / 1000;
- if (AEE_SUCCESS == IMEDIA_Play(pMe->m_pIMedia))
- {
- pMe->m_bPlayRec = TRUE;
- }
- if (pMe->m_eActiveWin == MPW_SONGPLAYER)
- {
- MP_UpdateProgCtl(pMe, pCmdNotify->nCmd, pCmdNotify->nSubCmd, nTextID);
- }
- }
- } // MM_CMD_GETTOTALTIME
- else if (pCmdNotify->nCmd == MM_CMD_SETMEDIAPARM)
- {
- if (pCmdNotify->nSubCmd == MM_PARM_VOLUME && pCmdNotify->nStatus == MM_STATUS_DONE)
- {
- IMEDIA_GetMediaParm(pMe->m_pIMedia, MM_PARM_VOLUME, NULL, NULL);
- return;
- }
- } // MM_CMD_SETMEDIAPARM
- else if (pCmdNotify->nCmd == MM_CMD_GETMEDIAPARM) // IMEDIA_GetMediaParm() events
- {
- if (pCmdNotify->nSubCmd == MM_PARM_VOLUME && pCmdNotify->nStatus == MM_STATUS_DONE)
- {
- pMe->m_wVolume = (uint16)(uint32)pCmdNotify->pCmdData;
- pMe->m_bProgTimer = FALSE;
- if (pMe->m_eActiveWin == MPW_SONGPLAYER)
- {
- MP_UpdateProgCtl(pMe, pCmdNotify->nCmd, pCmdNotify->nSubCmd, IDS_VOLUME);
- }
-
- pMe->m_bProgTimer = TRUE;
- }
- } // MM_CMD_GETMEDIAPARM
- }
- static boolean MP_IsPause(MediaPlayer * pApp)
- {
- boolean bChg;
- int nState = IMEDIA_GetState(pApp->m_pIMedia, &bChg);
-
- if (bChg)
- {
- return FALSE;
- }
- return (nState == MM_STATE_PLAY_PAUSE);
- }
- static void MP_UpdateProgCtl(MediaPlayer * pme, int nCmd, int nSubCmd, uint16 wResID)
- {
- char sz[32];
- AECHAR szBuf[32];
-
- if ( !ISHELL_LoadResString(pme->a.m_pIShell,
- RES_RES_FILE, wResID, pme->m_szText, sizeof(pme->m_szText)) )
- {
- pme->m_szText[0] = (AECHAR)0;
- }
- if (nCmd == MM_CMD_PLAY)
- {
- SPRINTF(sz,
- " %02d:%02d/%02d:%02d",
- pme->m_dwPlayPos/60,
- pme->m_dwPlayPos%60,
- pme->m_dwTotalTime/60,
- pme->m_dwTotalTime%60);
- STRTOWSTR(sz, szBuf, sizeof(szBuf));
- WSTRCAT(pme->m_szText, szBuf);
- if (pme->m_dwTotalTime)
- {
- pme->m_wPct = (uint16)((100 * pme->m_dwPlayPos) / pme->m_dwTotalTime);
-
- }
- }
- else if (nCmd == MM_CMD_GETTOTALTIME)
- {
- SPRINTF(sz,
- " %02d:%02d/%02d:%02d",
- pme->m_dwPlayPos/60,
- pme->m_dwPlayPos%60,
- pme->m_dwTotalTime/60,
- pme->m_dwTotalTime%60);
- STRTOWSTR(sz, szBuf, sizeof(szBuf));
- WSTRCAT(pme->m_szText, szBuf);
- }
- else if (nCmd == MM_CMD_GETMEDIAPARM && nSubCmd == MM_PARM_VOLUME)
- {
- SPRINTF(sz, "[%u]", pme->m_wVolume);
- STRTOWSTR(sz, szBuf, sizeof(szBuf));
- WSTRCAT(pme->m_szText, szBuf);
- pme->m_wPct = (100 * pme->m_wVolume) / AEE_MAX_VOLUME;
- }
- else
- {
- pme->m_wPct = 0;
- }
- CProgCtl_SetPos(pme, pme->m_szText, pme->m_wPct);
- IDISPLAY_Update(pme->a.m_pIDisplay);
- }
- static void CProgCtl_SetPos(MediaPlayer * pme, AECHAR * psz, uint16 wPct)
- {
- MP_FitStaticText(pme->a.m_pIDisplay, pme->m_pTitle, AEE_FONT_NORMAL, psz);
- ISTATIC_Redraw(pme->m_pTitle);
- CProgCtl_DrawHist(pme, wPct);
- MP_FrameRect(pme->a.m_pIDisplay, &pme->m_rectMain);
- }
- static void MP_FitStaticText(IDisplay * pd, IStatic * ps, AEEFont font, AECHAR * pszText)
- {
- int nFits;
- AEERect rect;
- int nLen = WSTRLEN(pszText);
- AECHAR chSave = (AECHAR)0;
- ISTATIC_GetRect(ps, &rect);
- IDISPLAY_MeasureTextEx(pd, font, pszText, -1, rect.dx, &nFits);
-
- if (nFits < nLen)
- {
- chSave = pszText[nFits];
- pszText[nFits] = (AECHAR)0;
- }
- ISTATIC_SetText(ps, NULL, pszText, AEE_FONT_NORMAL, font);
-
- if (nFits < nLen)
- {
- pszText[nFits] = chSave;
- }
- }
- static void CProgCtl_DrawHist(MediaPlayer * pme, uint16 wPct)
- {
- AEERect rc;
- MEMCPY(&rc, &pme->m_rectBar, sizeof(AEERect));
- if(wPct > 100)
- {
- wPct = 100;
- }
- IDISPLAY_DrawFrame(pme->a.m_pIDisplay, &rc, AEE_FT_RAISED, CLR_SYS_SCROLLBAR);
- rc.dx = (rc.dx * wPct) / 100;
- IDISPLAY_FillRect(pme->a.m_pIDisplay, &rc, MP_CLR_PROG_FILL);
- }
- static void MP_FrameRect(IDisplay * pd, AEERect * pRect)
- {
- RGBVAL clr = IDISPLAY_SetColor(pd, CLR_USER_FRAME, CLR_SYS_DK_SHADOW);
- IDISPLAY_FrameRect(pd, pRect);
- IDISPLAY_SetColor(pd, CLR_USER_FRAME, clr);
- }
- static boolean CProgCtl_Init(MediaPlayer * pme, AEERect * pRectMain)
- {
- AEERect rect;
- int x, y;
- int dxProg, dyProg;
- MEMCPY(&pme->m_rectMain, pRectMain, sizeof(AEERect));
- if (ISHELL_CreateInstance(pme->a.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;
- }