264 lines
6.1 KiB
C
264 lines
6.1 KiB
C
#include "mywin_inc.h"
|
|
#include "mywin_music.h"
|
|
#include "mp3play.h"
|
|
#include "system_updata.h"
|
|
|
|
|
|
#define WIN_MUSIC_TYPE "WIN_MusicStruct"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WIN_MusicStruct *WIN_CreatMusic (WIN_WindowStruct *base,
|
|
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
|
|
int x,int y,int x_size,int y_size)
|
|
{
|
|
//重设消息循环
|
|
if (msgLoop==0)
|
|
{
|
|
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))MUSIC_defaultMsgLoop;
|
|
}
|
|
|
|
WIN_MusicStruct *ret=mymalloc (sizeof ( WIN_MusicStruct));
|
|
//调用父类的构造函数
|
|
if (ret)
|
|
{
|
|
mymemset (ret,0,sizeof ( WIN_MusicStruct));
|
|
// if (0==WIN_CreatWindowExt((WIN_WindowStruct *)ret,base,msgLoop,x,y,x_size,y_size))
|
|
if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size))
|
|
{
|
|
//创建失败
|
|
myfree (ret);
|
|
ret=0;
|
|
}
|
|
else
|
|
{
|
|
((WIN_WindowStruct *)ret)->winType=WIN_MUSIC_TYPE;
|
|
((WIN_WindowStruct *)ret)->intercept=1;
|
|
((WIN_WindowStruct *)ret)->deleteWindow=(void (*)(struct _WIN_WindowStruct *win))WIN_DeleteMusic;
|
|
ret->timerId=WIN_CreatTimer((WIN_WindowStruct *)ret,1000);
|
|
//构造一个消息框
|
|
ret->title="音乐播放器";
|
|
ret->rectColor=0x221f18;
|
|
ret->txtColor=0xff00ff;
|
|
ret->selectRectColor=0x342f2a;
|
|
ret->selectTxtColor=0xc2ae9b;
|
|
}
|
|
}
|
|
|
|
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WIN_DeleteMusic (WIN_MusicStruct *music )
|
|
{
|
|
if (music->done==0)
|
|
{
|
|
mp3_stop();
|
|
while (1)
|
|
{
|
|
if (WIN_GetExWorkFunStat(music->work)) break;
|
|
WIN_Delay_ms(100);
|
|
}
|
|
WIN_ExWorkFunClear(music->work);
|
|
music->done=1;
|
|
}
|
|
|
|
if (music->mp3Data.data) myfree(music->mp3Data.data);
|
|
|
|
//调用父类的销毁函数
|
|
WIN_DeleteWindow ( (WIN_WindowStruct *)music);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//消息框的绘制函数
|
|
void MUSIC_DefaultPaint (WIN_MusicStruct *music)
|
|
{
|
|
int x=0;
|
|
int y=0;
|
|
int x_size=((WIN_WindowStruct *)music)->x_size;
|
|
int y_size=((WIN_WindowStruct *)music)->y_size;
|
|
char *txt_buff=mymalloc (128);
|
|
|
|
WIN_PaintBackGround ((WIN_WindowStruct *)music);
|
|
|
|
//显示标题
|
|
int img_x=x+25;
|
|
int img_y=y;
|
|
int img_xsize=0;
|
|
int img_ysize=0;
|
|
int head_ysize=45;
|
|
WIN_SetLcdColor (music->txtColor);
|
|
if (music->icon)
|
|
{
|
|
WIN_GetImageSize (music->icon,&img_xsize,&img_ysize);
|
|
if (img_ysize>head_ysize) img_ysize=head_ysize;
|
|
WIN_DrawImagByAlpha (img_x,img_y+head_ysize/2-img_ysize/2, img_xsize,img_ysize,music->icon,WIN_GetLcdColor16());
|
|
img_xsize+=10;
|
|
}
|
|
WIN_SetLcdColor (~music->txtColor);
|
|
WIN_DrawTxtAt (music->title,img_x+img_xsize+1,y+head_ysize/2-WIN_GetFontHight()/2);
|
|
WIN_DrawTxtAt (music->title,img_x+img_xsize-1,y+head_ysize/2-WIN_GetFontHight()/2);
|
|
WIN_DrawTxtAt (music->title,img_x+img_xsize,y+head_ysize/2-WIN_GetFontHight()/2+1);
|
|
WIN_DrawTxtAt (music->title,img_x+img_xsize,y+head_ysize/2-WIN_GetFontHight()/2-1);
|
|
WIN_SetLcdColor (music->txtColor);
|
|
WIN_DrawTxtAt (music->title,img_x+img_xsize,y+head_ysize/2-WIN_GetFontHight()/2);
|
|
|
|
sprintf (txt_buff,"文件:%s",music->mp3_file_name);
|
|
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*2/6-WIN_GetFontHight()/2);
|
|
|
|
sprintf (txt_buff,"歌曲:%s",music->mp3_title);
|
|
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*3/6-WIN_GetFontHight()/2);
|
|
|
|
sprintf (txt_buff,"艺术家:%s",music->mp3_artist);
|
|
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*4/6-WIN_GetFontHight()/2);
|
|
|
|
int cursec=music->cursec;
|
|
int totsec=music->totsec;
|
|
sprintf (txt_buff,"%02d:%02d/%02d:%02d",cursec/60,cursec%60,totsec/60,totsec%60);
|
|
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*5/6-WIN_GetFontHight()/2);
|
|
|
|
int line_xsize=x_size-(img_x+img_xsize)*2;
|
|
WIN_DrawRect (img_x+img_xsize,y_size-30,line_xsize,10);
|
|
WIN_FillRectByColor(img_x+img_xsize+1,y_size-30+1,line_xsize*music->cursec/music->totsec,10-2);
|
|
|
|
myfree(txt_buff);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//消息框的消息处理函数
|
|
void MUSIC_defaultMsgLoop (WIN_MusicStruct *music,WIN_MsgStruct *msg)
|
|
{
|
|
WIN_KeyStruct *k=0;
|
|
WIN_MoveStruct *m=0;
|
|
switch (msg->msg)
|
|
{
|
|
case WIN_MSG_PAINT:
|
|
MUSIC_DefaultPaint(music);
|
|
break;
|
|
case WIN_MSG_TIMER:
|
|
if (music->done==0)
|
|
{
|
|
if (WIN_GetExWorkFunStat(music->work))
|
|
{
|
|
//工作已经完成,
|
|
WIN_ExWorkFunClear (music->work);
|
|
WIN_DeleteTimer(music->timerId);
|
|
music->timerId=0;
|
|
music->done=1;
|
|
((WIN_WindowStruct *)music)->deleteWindow((WIN_WindowStruct *)music);
|
|
}
|
|
else
|
|
{
|
|
music->cursec= mp3_getAudiodev()->cursec;
|
|
music->totsec= mp3_getAudiodev()->totsec;
|
|
if ((music->mp3_title[0]==0)&&mp3_getMp3Info()->title[0])
|
|
{
|
|
mymemcpy (music->mp3_title,mp3_getMp3Info()->title,strlen((char *)mp3_getMp3Info()->title)+1);
|
|
}
|
|
if ((music->mp3_artist[0]==0)&&mp3_getMp3Info()->artist[0])
|
|
{
|
|
mymemcpy (music->mp3_artist,mp3_getMp3Info()->artist,strlen((char *)mp3_getMp3Info()->artist)+1);
|
|
}
|
|
}
|
|
WIN_SetInvalidWhenTop ((WIN_WindowStruct *)music);
|
|
}
|
|
break;
|
|
case WIN_MSG_MOVE:
|
|
m=msg->data.p;
|
|
switch (m->moveType)
|
|
{
|
|
case MOVE_DATA_LONG:
|
|
((WIN_WindowStruct *)music)->deleteWindow((WIN_WindowStruct *)music);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
break;
|
|
case WIN_MSG_KEY:
|
|
k=msg->data.p;
|
|
if (k->shortPress&KEY_VALUE_UP)//短按
|
|
{
|
|
mp3_play();
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_DOWN)
|
|
{
|
|
mp3_suspend();
|
|
}
|
|
else if (k->shortPress&KEY_VALUE_HOME)
|
|
{
|
|
((WIN_WindowStruct *)music)->deleteWindow((WIN_WindowStruct *)music);
|
|
}
|
|
if (k->shortPress)
|
|
{
|
|
WIN_SetInvalid ((WIN_WindowStruct *)music);
|
|
}
|
|
break;//case WIN_MSG_KEY:
|
|
default:
|
|
WIN_DefaultMsgLoop((WIN_WindowStruct *)music,msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int g_work (void *ptr)
|
|
{
|
|
DataInfo_Struct *dat=ptr;
|
|
return mp3_play_song (dat->data,dat->dataSize);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WIN_MusicStruct *MUSIC_PlaySong (WIN_WindowStruct *base,char *name)
|
|
{
|
|
u32 size=0;
|
|
u8 *data=SysFile_GetFileByName(name,&size);
|
|
if (data==0) return 0;
|
|
|
|
WIN_MusicStruct *ret=0;
|
|
if (base)
|
|
{
|
|
ret=WIN_CreatMusic (base,0,0,0,base->x_size,base->y_size);
|
|
}
|
|
else
|
|
{
|
|
ret=WIN_CreatMusic (0,0,0,0,WIN_GetBaseWindow()->x_size,50);
|
|
}
|
|
ret->mp3Data.data=data;
|
|
ret->mp3Data.dataSize=size;
|
|
mymemcpy(ret->mp3_file_name,name,strlen(name)+1);
|
|
|
|
//创建工作线程
|
|
ret->work=WIN_CreatThreadPro ((int (*)(void *))g_work,&ret->mp3Data,&ret->work_ret,17);
|
|
|
|
WIN_SetBackPicPath ((WIN_WindowStruct *)ret,base->pic_path);
|
|
WIN_ShowWindow((WIN_WindowStruct*)ret);
|
|
return ret;
|
|
}
|
|
|
|
|