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

📄 mysoundplayer.c

📁 在BREW平台下开发,用C语言写的适合作业,是实现声音接口的小程序,
💻 C
📖 第 1 页 / 共 2 页
字号:
/*===========================================================================

FILE: mysoundplayer.c
===========================================================================*/


/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEESound.h"			// Sound Interface definitions
#include "AEEStdlib.h"
#include "AEEHeap.h"
#include "AEEImage.h"
#include "AEEMenu.h"
#include "AEEFile.h"

#include "mysoundplayer.bid"

#define  RECT_X			8
#define  RECT_Y			34
#define  RECT_CX		113
#define  RECT_CY		3

#define  MENU_RECT_X		8
#define  MENU_RECT_Y		57
#define  MENU_RECT_CX		114
#define  MENU_RECT_CY		66

#define MP_MEDIA_DIR          "mp3/*.mp3"
#define MP_MAX_STRLEN         64
#define MP_MAX_FILES          32

#define MAX_FILE_NAME      AEE_MAX_FILE_NAME

#define MY_MENU_ID_M1	10001


/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "pMe->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _mysoundplayer {
	AEEApplet      a ;	       // First element of this structure must be AEEApplet
    AEEDeviceInfo  DeviceInfo; // always have access to the hardware device information
    IDisplay      *pIDisplay;  // give a standard way to access the Display interface
    IShell        *pIShell;    // give a standard way to access the Shell interface
	ISoundPlayer	*pISoundPlayer;		//指向SoundPlayer的指针
	uint32			TotalTime;			//歌曲总时间长度(ms)
	uint16		    PlayTime;			//当前时间
	int				ref;				//进入回调函数的次数
	AEERect			rect;
	AEERect			total_rect;			//
	IMenuCtl	    *pIMenuCtl;
    char           m_szFileArray[MP_MAX_FILES][MP_MAX_STRLEN ];
	uint16			NumFiles;       

    // add your own variables here...



} mysoundplayer;

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static  boolean mysoundplayer_HandleEvent(mysoundplayer* pMe, AEEEvent eCode, 
                                             uint16 wParam, uint32 dwParam);
boolean mysoundplayer_InitAppData(mysoundplayer* pMe);
void    mysoundplayer_FreeAppData(mysoundplayer* pMe);
static void		SoundPlayerCBFn(void *pUser, AEESoundPlayerCmd eCBType, AEESoundPlayerStatus eStatus, uint32 dwParam);
void DrawPlayStatus(mysoundplayer* pMe);
void draw_back_rect(mysoundplayer* pMe);

boolean my_init_menu(mysoundplayer* pMe);
void get_file_list(mysoundplayer* pMe);
static char *     get_file_name(const char * psz);

/*===============================================================================
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_MYSOUNDPLAYER )
	{
		// Create the applet and make room for the applet structure
		if( AEEApplet_New(sizeof(mysoundplayer),
                          ClsId,
                          pIShell,
                          po,
                          (IApplet**)ppObj,
                          (AEEHANDLER)mysoundplayer_HandleEvent,
                          (PFNFREEAPPDATA)mysoundplayer_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(mysoundplayer_InitAppData((mysoundplayer*)*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

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 SampleAppWizard_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 AEEClsCreateInstance() 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 mysoundplayer_HandleEvent(mysoundplayer* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
RGBVAL clrFrame;
RGBVAL clrFill;
AEESoundPlayerInfo pinfo;
IImage *pImage;
//IHeap  *pIHeap;
//uint32 dwSize = 100000;


    switch (eCode) 
	{
        // App is told it is starting up
        case EVT_APP_START:                        
		    // Add your code here...

			//显示播放器背景图片
			pImage = ISHELL_LoadImage(pMe->pIShell,"player.bmp");
			IIMAGE_Draw(pImage,0,0);
			IIMAGE_Release(pImage);

			//创建声音接口
			ISHELL_CreateInstance(pMe->pIShell,AEECLSID_SOUNDPLAYER,&pMe->pISoundPlayer);
			
			//显示内存使用情况,用于调试
//--------------------------------
/*			ISHELL_CreateInstance(pMe->pIShell,AEECLSID_HEAP,&pIHeap);

			if (IHEAP_CheckAvail(pIHeap,dwSize)) 
				DBGPRINTF(" there 's have %d",dwSize);
			else
				DBGPRINTF(" there 's not have %d",dwSize);
			DBGPRINTF(" there 's have used %d before open" , IHEAP_GetMemStats(pIHeap) );

//--------------------------------
*/
			ISOUNDPLAYER_RegisterNotify(pMe->pISoundPlayer,SoundPlayerCBFn,(void *)pMe);

			//=== 获取歌曲列表,所有mp3文件名存放在pMe->m_szFileArray 数组中
			get_file_list(pMe);

			//=== 建立播放歌曲列表的菜单 ==============
			my_init_menu(pMe);

            return(TRUE);


        // App is told it is exiting
        case EVT_APP_STOP:
            // Add your code here...

      		return(TRUE);


        // App is being suspended 
        case EVT_APP_SUSPEND:
		    // Add your code here...

      		return(TRUE);


        // App is being resumed
        case EVT_APP_RESUME:
		    // Add your code here...

      		return(TRUE);


        // An SMS message has arrived for this app. Message is in the dwParam above as (char *)
        // sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
        case EVT_APP_MESSAGE:
		    // Add your code here...

      		return(TRUE);


        case EVT_COMMAND:
//			DBGPRINTF("the wParam is%d ",wParam);
		    // Add your code here...
			//==================================================================
			//   当用户在某个歌曲上按下了ok键(即选中了某个菜单项),则:
			//   1。先将菜单置为不活动
			//   2。将要播放的歌曲信息填入AEESoundPlayerInfo结构类型的pinfo中
			//      歌曲文件名 根据菜单序号取自于pMe->m_szFileArray数组
			//   3。调用ISOUNDPLAYER_SetInfo获取总时间,总时间再回调函数中得到
			//      并在回调函数中,得到总时间后,调用ISOUNDPLAYER_Play开始播放
			//===================================================================
				IMENUCTL_SetActive(pMe->pIMenuCtl,FALSE);
				pinfo.eInput = SDT_FILE;
				pinfo.pData = pMe->m_szFileArray[wParam-MY_MENU_ID_M1];
				pinfo.dwSize = NULL;

				if(ISOUNDPLAYER_SetInfo(pMe->pISoundPlayer,&pinfo) == AEE_SUCCESS)
				{
					ISOUNDPLAYER_GetTotalTime(pMe->pISoundPlayer);  //如果设置成功,则获取总时间
				}
      		return(TRUE);





        // A key was pressed. Look at the wParam above to see which key was pressed. The key
        // codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
        case EVT_KEY:
		    // Add your code here...
			if((pMe->pIMenuCtl != NULL)&&(IMENUCTL_IsActive(pMe->pIMenuCtl))){
				if(IMENUCTL_HandleEvent(pMe->pIMenuCtl,eCode,wParam,dwParam))
				{
					return TRUE;
				}
			}


			switch(wParam)
			{
			case AVK_1:
				ISOUNDPLAYER_Play(pMe->pISoundPlayer);
				break;
			case AVK_2:
				ISOUNDPLAYER_GetTotalTime(pMe->pISoundPlayer);

				break;
			case AVK_3:
				ISOUNDPLAYER_Resume(pMe->pISoundPlayer);

				break;
			case AVK_4:
				break;
			case AVK_5:
				break;
			case AVK_6:
				break;
			case AVK_UP:
				break;
			case AVK_DOWN:
				break;
			case AVK_LEFT:
				break;
			case AVK_RIGHT:
				break;
			default:
				break;
			}

      		return(TRUE);


        // If nothing fits up to this point then we'll just break out
        default:
            break;
   }

   return FALSE;
}

⌨️ 快捷键说明

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