Files
player/Project/Src/MyWinApp/mywin_music.c

264 lines
6.1 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#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)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
2025-06-27 00:32:57 +08:00
if (msgLoop==0)
{
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))MUSIC_defaultMsgLoop;
}
WIN_MusicStruct *ret=mymalloc (sizeof ( WIN_MusicStruct));
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
2025-06-27 00:32:57 +08:00
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))
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
2025-06-27 00:32:57 +08:00
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);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
ret->title="<EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
2025-06-27 00:32:57 +08:00
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);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_DeleteWindow ( (WIN_WindowStruct *)music);
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD>Ļ<EFBFBD><C4BB>ƺ<EFBFBD><C6BA><EFBFBD>
2025-06-27 00:32:57 +08:00
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);
2025-07-05 19:47:28 +08:00
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
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);
2025-07-05 19:47:28 +08:00
sprintf (txt_buff,"<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>%s",music->mp3_file_name);
2025-06-27 00:32:57 +08:00
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*2/6-WIN_GetFontHight()/2);
2025-07-05 19:47:28 +08:00
sprintf (txt_buff,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%s",music->mp3_title);
2025-06-27 00:32:57 +08:00
WIN_DrawTxtAt (txt_buff,img_x+img_xsize,y_size*3/6-WIN_GetFontHight()/2);
2025-07-05 19:47:28 +08:00
sprintf (txt_buff,"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ң<EFBFBD>%s",music->mp3_artist);
2025-06-27 00:32:57 +08:00
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);
}
2025-07-05 19:47:28 +08:00
//<2F><>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
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))
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ɣ<EFBFBD>
2025-06-27 00:32:57 +08:00
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;
2025-07-05 19:47:28 +08:00
if (k->shortPress&KEY_VALUE_UP)//<2F>̰<EFBFBD>
2025-06-27 00:32:57 +08:00
{
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);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>
2025-06-27 00:32:57 +08:00
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;
}