2009-12-01 23:31:48 +08:00
|
|
|
|
#include <rtgui/rtgui.h>
|
|
|
|
|
#include <rtgui/image.h>
|
|
|
|
|
#include <rtgui/rtgui_system.h>
|
|
|
|
|
|
|
|
|
|
#include <rtgui/widgets/view.h>
|
2010-02-25 00:05:37 +08:00
|
|
|
|
#include <rtgui/widgets/label.h>
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#include <rtgui/widgets/list_view.h>
|
2009-12-01 23:31:48 +08:00
|
|
|
|
#include <rtgui/widgets/workbench.h>
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#include <rtgui/widgets/filelist_view.h>
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#include <string.h>
|
2009-12-01 23:31:48 +08:00
|
|
|
|
#include <dfs_posix.h>
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#include "mp3.h"
|
|
|
|
|
#include "picture.h"
|
2009-12-01 23:31:48 +08:00
|
|
|
|
#include "player_ui.h"
|
|
|
|
|
#include "player_bg.h"
|
|
|
|
|
#include "play_list.h"
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#include "station_list.h"
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
#include "play.hdh"
|
|
|
|
|
#include "stop.hdh"
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
#define RADIO_FN "/radio.pls"
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-22 04:41:42 +08:00
|
|
|
|
const static char *time_bg_xpm[] = {
|
|
|
|
|
"48 20 7 1",
|
|
|
|
|
". c #007DC6",
|
|
|
|
|
"+ c #0079C6",
|
|
|
|
|
"@ c #0079BD",
|
|
|
|
|
"# c #0075BD",
|
|
|
|
|
"$ c #0071BD",
|
|
|
|
|
"% c #0071B5",
|
|
|
|
|
"& c #006DB5",
|
|
|
|
|
"................................................",
|
|
|
|
|
"................................................",
|
|
|
|
|
"................................................",
|
|
|
|
|
"................................................",
|
|
|
|
|
"................................................",
|
|
|
|
|
"++++++++++++++++++++++++++++++++++++++++++++++++",
|
|
|
|
|
"++++++++++++++++++++++++++++++++++++++++++++++++",
|
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
|
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
|
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
|
|
|
|
|
"################################################",
|
|
|
|
|
"################################################",
|
|
|
|
|
"################################################",
|
|
|
|
|
"################################################",
|
|
|
|
|
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
|
|
|
|
|
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
|
|
|
|
|
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
|
|
|
|
|
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
|
|
|
|
|
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
|
|
|
|
|
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
|
|
|
|
|
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"};
|
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
static struct rtgui_view* home_view;
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static struct rtgui_list_view* function_view;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
static struct rtgui_workbench* workbench;
|
|
|
|
|
static rtgui_timer_t* info_timer;
|
|
|
|
|
static rt_thread_t player_ui_tid = RT_NULL;
|
|
|
|
|
static enum PLAYER_MODE player_mode = PLAYER_STOP;
|
|
|
|
|
static enum PLAYER_STEP next_step = PLAYER_STEP_STOP;
|
|
|
|
|
static struct tag_info tinfo;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
static rt_uint32_t play_time;
|
|
|
|
|
static rtgui_image_t *time_bg_image;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
void player_play_file(const char* fn);
|
|
|
|
|
void player_play_url(const char* url);
|
2010-02-09 07:45:21 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
rtgui_color_t saved;
|
|
|
|
|
|
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
|
|
|
|
|
if (dc == RT_NULL) return ;
|
|
|
|
|
|
|
|
|
|
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
|
|
|
|
|
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212) / tinfo.duration, 75);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226)
|
2010-02-09 07:45:21 +08:00
|
|
|
|
{
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212) / tinfo.duration, 226, 75);
|
|
|
|
|
}
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
|
|
|
|
|
|
|
|
|
|
if (player_mode == PLAYER_PLAY_FILE)
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
char line[32];
|
|
|
|
|
|
|
|
|
|
play_time++;
|
|
|
|
|
rt_snprintf(line, sizeof(line), "%3d:%02d", play_time / 60, play_time % 60);
|
|
|
|
|
|
|
|
|
|
rect.x1 = 172; rect.y1 = 39;
|
|
|
|
|
rect.x2 = 220; rect.y2 = 59;
|
|
|
|
|
rtgui_image_blit(time_bg_image, dc, &rect);
|
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
2010-02-09 07:45:21 +08:00
|
|
|
|
}
|
2010-02-17 17:16:05 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void player_update_tag_info(struct rtgui_dc* dc)
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
char line[32];
|
|
|
|
|
rtgui_color_t saved;
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_image_t *background;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
saved = rtgui_dc_get_color(dc);
|
|
|
|
|
rtgui_dc_set_color(dc, black);
|
|
|
|
|
|
|
|
|
|
rect.x1 = 0; rect.y1 = 0;
|
|
|
|
|
rect.x2 = 240; rect.y2 = 65;
|
|
|
|
|
/* draw background */
|
2010-02-22 04:41:42 +08:00
|
|
|
|
background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
if (background != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_image_blit(background, dc, &rect);
|
|
|
|
|
rtgui_image_destroy(background);
|
|
|
|
|
|
|
|
|
|
background = RT_NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* draw playing information */
|
|
|
|
|
rect.x1 = 28; rect.y1 = 12;
|
|
|
|
|
rect.x2 = 220; rect.y2 = rect.y1 + 16;
|
|
|
|
|
if (player_mode == PLAYER_STOP)
|
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rt_snprintf(line, sizeof(line), "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rtgui_dc_draw_text(dc, tinfo.title, &rect);
|
|
|
|
|
|
|
|
|
|
rect.x1 = 28; rect.y1 = 39;
|
|
|
|
|
rect.x2 = 220; rect.y2 = 59;
|
|
|
|
|
if (player_mode == PLAYER_STOP)
|
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
|
|
|
|
|
|
2010-02-09 07:45:21 +08:00
|
|
|
|
if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
play_time = 0;
|
|
|
|
|
|
|
|
|
|
rect.x1 = 172;
|
|
|
|
|
rt_snprintf(line, sizeof(line), " 0:00");
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtgui_dc_set_color(dc, saved);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
char *pos, *next;
|
|
|
|
|
rt_uint32_t length;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
length = read(fd, line, line_size);
|
|
|
|
|
if (length > 0)
|
|
|
|
|
{
|
|
|
|
|
pos = strstr(line, "\r\n");
|
|
|
|
|
if (pos == RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
pos = strstr(line, "\n");
|
|
|
|
|
next = pos ++;
|
|
|
|
|
}
|
|
|
|
|
else next = pos + 2;
|
2010-02-09 06:34:40 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
if (pos != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
*pos = '\0';
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
/* move back */
|
|
|
|
|
lseek(fd, -(length - (next - line)), SEEK_CUR);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
length = pos - line;
|
|
|
|
|
}
|
|
|
|
|
else length = 0;
|
|
|
|
|
}
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
return length;
|
2010-02-09 07:45:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void function_play_radio(void* parameter)
|
2010-02-09 07:45:21 +08:00
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
struct station_list* list;
|
|
|
|
|
struct station_item* item;
|
2010-02-09 07:45:21 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
list = station_list_create(RADIO_FN);
|
|
|
|
|
if (list != RT_NULL)
|
2010-02-09 07:45:21 +08:00
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
item = station_list_select(list, workbench);
|
|
|
|
|
if (item != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
player_play_url(item->url);
|
|
|
|
|
}
|
2010-02-09 07:45:21 +08:00
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
station_list_destroy(list);
|
2010-02-09 07:45:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void function_filelist(void* parameter)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t rect;
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_filelist_view_t *view;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
2010-02-18 07:56:49 +08:00
|
|
|
|
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
if (view != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
|
|
|
|
|
{
|
|
|
|
|
char fn[64];
|
|
|
|
|
|
|
|
|
|
/* get open file */
|
|
|
|
|
rt_snprintf(fn, 64, "%s/%s", view->current_directory,
|
|
|
|
|
view->items[view->current_item].name);
|
|
|
|
|
|
|
|
|
|
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
|
2010-02-09 07:45:21 +08:00
|
|
|
|
strstr(view->items[view->current_item].name , ".MP3") != RT_NULL ||
|
|
|
|
|
strstr(view->items[view->current_item].name , ".wav") != RT_NULL ||
|
|
|
|
|
strstr(view->items[view->current_item].name , ".WAV") != RT_NULL)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
/* clear old play list */
|
|
|
|
|
play_list_clear();
|
|
|
|
|
play_list_append(fn);
|
|
|
|
|
|
|
|
|
|
player_mode = PLAYER_PLAY_FILE;
|
|
|
|
|
next_step = PLAYER_STEP_STOP;
|
2010-02-09 07:45:21 +08:00
|
|
|
|
player_play_file(play_list_start());
|
2009-12-01 23:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
|
|
|
|
|
strstr(view->items[view->current_item].name , ".M3U") != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
/* read all of music filename to a list */
|
|
|
|
|
int fd;
|
|
|
|
|
char line[64];
|
|
|
|
|
|
|
|
|
|
fd = open(fn, O_RDONLY, 0);
|
|
|
|
|
if (fd >= 0)
|
|
|
|
|
{
|
|
|
|
|
rt_uint32_t length;
|
|
|
|
|
|
|
|
|
|
length = read_line(fd, line, sizeof(line));
|
2010-02-09 06:34:40 +08:00
|
|
|
|
/* clear old play list */
|
|
|
|
|
play_list_clear();
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
2010-02-09 06:34:40 +08:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
length = read_line(fd, line, sizeof(line));
|
|
|
|
|
if (length > 0)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
if (strstr(line, "http:") != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
play_list_append(line);
|
|
|
|
|
}
|
|
|
|
|
else if (line[0] != '/')
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rt_snprintf(fn, sizeof(fn), "%s/%s", view->current_directory, line);
|
2010-02-09 06:34:40 +08:00
|
|
|
|
play_list_append(fn);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
}
|
2010-02-09 06:34:40 +08:00
|
|
|
|
else play_list_append(line);
|
|
|
|
|
}
|
|
|
|
|
} while (length > 0);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
|
|
if (play_list_items() > 0)
|
|
|
|
|
{
|
|
|
|
|
player_mode = PLAYER_PLAY_FILE;
|
|
|
|
|
next_step = PLAYER_STEP_NEXT;
|
2010-02-09 07:45:21 +08:00
|
|
|
|
player_play_file(play_list_start());
|
2009-12-01 23:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* destroy view */
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_filelist_view_destroy(view);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void function_device(void* parameter)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
rtgui_view_t *view;
|
|
|
|
|
extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench);
|
|
|
|
|
|
|
|
|
|
view = device_view_create(workbench);
|
|
|
|
|
if (view != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_view_show(view, RT_FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void function_player(void* parameter)
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
rtgui_view_show(home_view, RT_FALSE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
static void function_show_picure(void* parameter)
|
2010-02-17 19:00:04 +08:00
|
|
|
|
{
|
|
|
|
|
rtgui_view_t *view;
|
|
|
|
|
|
|
|
|
|
view = picture_view_create(workbench);
|
|
|
|
|
if (view != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_view_show(view, RT_TRUE);
|
|
|
|
|
rtgui_view_destroy(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
void function_action(void* parameter)
|
|
|
|
|
{
|
|
|
|
|
rt_kprintf("item action!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
void function_cable(void* parameter)
|
2010-02-17 17:16:05 +08:00
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
extern void USB_cable(void);
|
2010-02-17 17:16:05 +08:00
|
|
|
|
USB_cable();
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
const struct rtgui_list_item function_list[] =
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-09 07:45:21 +08:00
|
|
|
|
{"ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨", RT_NULL, function_play_radio, RT_NULL},
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{"<EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>̨", RT_NULL, function_action, RT_NULL},
|
|
|
|
|
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>", RT_NULL, function_filelist, RT_NULL},
|
2010-02-17 19:00:04 +08:00
|
|
|
|
{"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ", RT_NULL, function_show_picure, RT_NULL},
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{"<EFBFBD>豸<EFBFBD><EFBFBD>Ϣ", RT_NULL, function_device, RT_NULL},
|
|
|
|
|
{"ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", RT_NULL, function_action, RT_NULL},
|
2010-02-17 17:16:05 +08:00
|
|
|
|
{"USB <20><><EFBFBD><EFBFBD>", RT_NULL, function_cable, RT_NULL},
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{"<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", RT_NULL, function_player, RT_NULL},
|
|
|
|
|
};
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
void player_set_position(rt_uint32_t position)
|
|
|
|
|
{
|
|
|
|
|
if (player_mode != PLAYER_PLAY_RADIO)
|
|
|
|
|
{
|
|
|
|
|
tinfo.position = position / (tinfo.bit_rate / 8);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tinfo.position = position;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_set_title(const char* title)
|
|
|
|
|
{
|
|
|
|
|
strncpy(tinfo.title, title, 40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_set_buffer_status(rt_bool_t buffering)
|
|
|
|
|
{
|
|
|
|
|
if (buffering == RT_TRUE)
|
|
|
|
|
strncpy(tinfo.artist, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...", 40);
|
|
|
|
|
else
|
|
|
|
|
strncpy(tinfo.artist, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...", 40);
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-22 21:35:47 +08:00
|
|
|
|
enum PLAYER_MODE player_get_mode()
|
|
|
|
|
{
|
|
|
|
|
return player_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 07:56:49 +08:00
|
|
|
|
void player_play_file(const char* fn)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
rtgui_color_t saved;
|
|
|
|
|
rt_bool_t is_mp3;
|
|
|
|
|
|
|
|
|
|
is_mp3 = RT_FALSE;
|
|
|
|
|
|
|
|
|
|
if (strstr(fn, ".mp3") != RT_NULL ||
|
|
|
|
|
strstr(fn, ".MP3") != RT_NULL)
|
|
|
|
|
is_mp3 = RT_TRUE;
|
|
|
|
|
else if (strstr(fn, ".wav") != RT_NULL ||
|
|
|
|
|
strstr(fn, ".wav") != RT_NULL)
|
|
|
|
|
is_mp3 = RT_FALSE;
|
|
|
|
|
else return; /* not supported audio format */
|
|
|
|
|
|
|
|
|
|
if (is_mp3 == RT_TRUE)
|
|
|
|
|
{
|
|
|
|
|
/* get music tag information */
|
|
|
|
|
mp3_get_info(fn, &tinfo);
|
|
|
|
|
if (tinfo.title[0] == '\0')
|
|
|
|
|
rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪<CEB4><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>>");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* wav file */
|
|
|
|
|
rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪<CEB4><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>>");
|
|
|
|
|
rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav<61><76><EFBFBD><EFBFBD>>");
|
|
|
|
|
|
|
|
|
|
tinfo.duration = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set player mode */
|
|
|
|
|
player_mode = PLAYER_PLAY_FILE;
|
|
|
|
|
|
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
|
|
|
|
|
if (dc != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t play_rect;
|
|
|
|
|
rtgui_image_t *button;
|
|
|
|
|
|
|
|
|
|
/* update tag information */
|
|
|
|
|
player_update_tag_info(dc);
|
|
|
|
|
|
|
|
|
|
/* reset progress bar */
|
|
|
|
|
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
|
|
|
|
|
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
|
|
|
|
|
|
|
|
|
|
/* update play button */
|
|
|
|
|
button = rtgui_image_create_from_mem("hdc",
|
|
|
|
|
play_hdh, sizeof(play_hdh), RT_FALSE);
|
|
|
|
|
play_rect.x1 = 32; play_rect.y1 = 92;
|
|
|
|
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
|
|
|
|
rtgui_image_blit(button, dc, &play_rect);
|
|
|
|
|
rtgui_image_destroy(button);
|
|
|
|
|
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtgui_view_show(home_view, RT_FALSE);
|
|
|
|
|
|
|
|
|
|
player_play_req(fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_play_url(const char* url)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
|
|
|
|
|
/* set music tag information */
|
|
|
|
|
strncpy(tinfo.title, "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨", 40);
|
|
|
|
|
player_set_buffer_status(RT_TRUE);
|
|
|
|
|
tinfo.duration = 320 * 1024; /* 320 k */
|
|
|
|
|
|
|
|
|
|
/* set player mode */
|
|
|
|
|
player_mode = PLAYER_PLAY_RADIO;
|
|
|
|
|
|
|
|
|
|
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
|
|
|
|
|
if (dc != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_rect_t play_rect;
|
|
|
|
|
rtgui_image_t *button;
|
|
|
|
|
|
|
|
|
|
/* update tag information */
|
|
|
|
|
player_update_tag_info(dc);
|
|
|
|
|
|
|
|
|
|
/* update play button */
|
|
|
|
|
button = rtgui_image_create_from_mem("hdc",
|
|
|
|
|
play_hdh, sizeof(play_hdh), RT_FALSE);
|
|
|
|
|
play_rect.x1 = 32; play_rect.y1 = 92;
|
|
|
|
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
|
|
|
|
rtgui_image_blit(button, dc, &play_rect);
|
|
|
|
|
rtgui_image_destroy(button);
|
|
|
|
|
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtgui_view_show(home_view, RT_FALSE);
|
|
|
|
|
|
|
|
|
|
player_play_req(url);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type == RTGUI_EVENT_PAINT)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
struct rtgui_rect rect;
|
|
|
|
|
rtgui_color_t saved;
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_image_t *background;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
|
|
|
|
if (dc == RT_NULL) return RT_FALSE;
|
|
|
|
|
rtgui_widget_get_rect(widget, &rect);
|
|
|
|
|
saved = RTGUI_WIDGET_FOREGROUND(widget);
|
|
|
|
|
|
|
|
|
|
/* draw background */
|
2010-02-22 04:41:42 +08:00
|
|
|
|
background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
if (background != RT_NULL)
|
|
|
|
|
{
|
|
|
|
|
rtgui_image_t *play;
|
|
|
|
|
rtgui_rect_t play_rect;
|
|
|
|
|
|
|
|
|
|
rtgui_image_blit(background, dc, &rect);
|
|
|
|
|
rtgui_image_destroy(background);
|
|
|
|
|
|
|
|
|
|
background = RT_NULL;
|
|
|
|
|
|
|
|
|
|
if (player_mode == PLAYER_STOP)
|
2010-02-22 04:41:42 +08:00
|
|
|
|
play = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
else
|
2010-02-22 04:41:42 +08:00
|
|
|
|
play = rtgui_image_create_from_mem("hdc", play_hdh, sizeof(play_hdh), RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
play_rect.x1 = 32; play_rect.y1 = 92;
|
|
|
|
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
|
|
|
|
rtgui_image_blit(play, dc, &play_rect);
|
|
|
|
|
rtgui_image_destroy(play);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rtgui_dc_fill_rect(dc, &rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* draw playing information */
|
|
|
|
|
rtgui_dc_set_color(dc, black);
|
|
|
|
|
{
|
|
|
|
|
char line[32];
|
|
|
|
|
|
|
|
|
|
rect.x1 = 28; rect.y1 = 12;
|
|
|
|
|
rect.x2 = 220; rect.y2 = rect.y1 + 16;
|
|
|
|
|
if (player_mode == PLAYER_STOP)
|
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rt_snprintf(line, sizeof(line), "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rtgui_dc_draw_text(dc, tinfo.title, &rect);
|
|
|
|
|
|
|
|
|
|
rect.x1 = 28; rect.y1 = 39;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rect.x2 = 170; rect.y2 = 59;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
if (player_mode == PLAYER_STOP)
|
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rect.x2 = 220;
|
|
|
|
|
rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
|
|
|
|
|
|
2010-02-09 07:45:21 +08:00
|
|
|
|
if ((tinfo.duration != 0) && (player_mode == PLAYER_PLAY_FILE))
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rt_uint32_t t = player_mode == PLAYER_STOP ? tinfo.duration : play_time;
|
|
|
|
|
|
|
|
|
|
rect.x1 = 172; rect.x2 = 220;
|
|
|
|
|
rt_snprintf(line, sizeof(line), "%3d:%02d", t / 60, t % 60);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
|
|
|
|
|
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
|
|
|
|
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = saved;
|
|
|
|
|
|
|
|
|
|
if (player_mode == PLAYER_PLAY_FILE)
|
|
|
|
|
{
|
|
|
|
|
char line[32];
|
|
|
|
|
rt_uint32_t index;
|
|
|
|
|
struct play_item* item;
|
|
|
|
|
|
|
|
|
|
rect.x1 = 20; rect.y1 = 150;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rect.x2 = 170; rect.y2 = 168;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
for (index = 0; index < play_list_items() && index < 8; index ++)
|
|
|
|
|
{
|
|
|
|
|
item = play_list_item(index);
|
|
|
|
|
rtgui_dc_draw_text(dc, item->title, &rect);
|
|
|
|
|
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rect.x1 = 172; rect.x2 = 220;
|
|
|
|
|
rt_snprintf(line, sizeof(line), "%3d:%02d", item->duration / 60, item->duration % 60);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rtgui_dc_draw_text(dc, line, &rect);
|
|
|
|
|
|
|
|
|
|
/* move to next item */
|
2010-02-22 04:41:42 +08:00
|
|
|
|
rect.x1 = 20; rect.x2 = 170;
|
2009-12-01 23:31:48 +08:00
|
|
|
|
rect.y1 += 18; rect.y2 += 18;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
|
|
|
|
|
return RT_FALSE;
|
|
|
|
|
}
|
|
|
|
|
else if (event->type == RTGUI_EVENT_KBD)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
|
|
|
|
if (ekbd->type == RTGUI_KEYDOWN)
|
|
|
|
|
{
|
|
|
|
|
switch (ekbd->key)
|
|
|
|
|
{
|
|
|
|
|
case RTGUIK_RIGHT:
|
|
|
|
|
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
|
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
player_stop_req();
|
2009-12-01 23:31:48 +08:00
|
|
|
|
next_step = PLAYER_STEP_NEXT;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
case RTGUIK_LEFT:
|
|
|
|
|
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
|
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
player_stop_req();
|
2009-12-01 23:31:48 +08:00
|
|
|
|
next_step = PLAYER_STEP_PREV;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RTGUIK_RETURN:
|
|
|
|
|
if (player_is_playing() == RT_TRUE)
|
|
|
|
|
{
|
2010-02-18 07:56:49 +08:00
|
|
|
|
player_stop_req();
|
2009-12-01 23:31:48 +08:00
|
|
|
|
next_step = PLAYER_STEP_STOP;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((player_mode == PLAYER_STOP) && (play_list_items() > 0))
|
|
|
|
|
{
|
|
|
|
|
next_step = PLAYER_STEP_NEXT;
|
2010-02-09 07:45:21 +08:00
|
|
|
|
player_play_file(play_list_current_item());
|
2009-12-01 23:31:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RTGUIK_DOWN:
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return RT_FALSE;
|
|
|
|
|
}
|
|
|
|
|
else if (event->type == RTGUI_EVENT_COMMAND)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
|
|
|
|
|
|
|
|
|
|
switch (ecmd->command_id)
|
|
|
|
|
{
|
|
|
|
|
case PLAYER_REQUEST_PLAY_SINGLE_FILE:
|
|
|
|
|
case PLAYER_REQUEST_PLAY_LIST:
|
|
|
|
|
rtgui_timer_start(info_timer);
|
|
|
|
|
break;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
case PLAYER_REQUEST_STOP:
|
|
|
|
|
{
|
|
|
|
|
rtgui_timer_stop(info_timer);
|
|
|
|
|
|
|
|
|
|
switch (next_step)
|
|
|
|
|
{
|
|
|
|
|
case PLAYER_STEP_STOP:
|
2010-02-22 21:35:47 +08:00
|
|
|
|
// #define TEST_MODE
|
|
|
|
|
#ifdef TEST_MODE
|
|
|
|
|
player_play_file(play_list_start());
|
|
|
|
|
next_step = PLAYER_STEP_STOP;
|
|
|
|
|
#else
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
rtgui_color_t saved;
|
|
|
|
|
rtgui_image_t *button;
|
|
|
|
|
rtgui_rect_t play_rect;
|
|
|
|
|
|
|
|
|
|
player_mode = PLAYER_STOP;
|
|
|
|
|
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
|
|
|
|
if (dc == RT_NULL) return RT_FALSE;
|
2010-02-17 17:16:05 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
player_update_tag_info(dc);
|
|
|
|
|
|
2010-02-09 06:34:40 +08:00
|
|
|
|
saved = RTGUI_WIDGET_FOREGROUND(widget);
|
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
|
|
|
|
|
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
2010-02-17 17:16:05 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
/* update play button */
|
2010-02-22 04:41:42 +08:00
|
|
|
|
button = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
play_rect.x1 = 32; play_rect.y1 = 92;
|
|
|
|
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
|
|
|
|
rtgui_image_blit(button, dc, &play_rect);
|
|
|
|
|
rtgui_image_destroy(button);
|
2010-02-17 17:16:05 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = saved;
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
2010-02-22 21:35:47 +08:00
|
|
|
|
#endif
|
2009-12-01 23:31:48 +08:00
|
|
|
|
break;
|
2010-02-22 04:41:42 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
case PLAYER_STEP_NEXT:
|
|
|
|
|
if (play_list_is_end() == RT_TRUE)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_dc* dc;
|
|
|
|
|
rtgui_color_t saved;
|
|
|
|
|
rtgui_image_t *button;
|
|
|
|
|
rtgui_rect_t play_rect;
|
2010-02-17 17:16:05 +08:00
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
/* set stat */
|
|
|
|
|
next_step = PLAYER_STEP_STOP;
|
|
|
|
|
player_mode = PLAYER_STOP;
|
|
|
|
|
|
|
|
|
|
/* update UI */
|
|
|
|
|
dc = rtgui_dc_begin_drawing(widget);
|
|
|
|
|
if (dc == RT_NULL) return RT_FALSE;
|
|
|
|
|
|
|
|
|
|
player_update_tag_info(dc);
|
|
|
|
|
|
2010-02-09 06:34:40 +08:00
|
|
|
|
saved = RTGUI_WIDGET_FOREGROUND(widget);
|
|
|
|
|
|
2009-12-01 23:31:48 +08:00
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
|
|
|
|
|
rtgui_dc_draw_hline(dc, 14, 226, 75);
|
|
|
|
|
|
|
|
|
|
/* update play button */
|
|
|
|
|
button = rtgui_image_create_from_mem("hdc",
|
|
|
|
|
stop_hdh, sizeof(stop_hdh), RT_FALSE);
|
|
|
|
|
play_rect.x1 = 32; play_rect.y1 = 92;
|
|
|
|
|
play_rect.x2 = 61; play_rect.y2 = 114;
|
|
|
|
|
rtgui_image_blit(button, dc, &play_rect);
|
|
|
|
|
rtgui_image_destroy(button);
|
|
|
|
|
|
|
|
|
|
RTGUI_WIDGET_FOREGROUND(widget) = saved;
|
|
|
|
|
rtgui_dc_end_drawing(dc);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-02-09 07:45:21 +08:00
|
|
|
|
player_play_file(play_list_next());
|
2009-12-01 23:31:48 +08:00
|
|
|
|
next_step = PLAYER_STEP_NEXT;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PLAYER_STEP_PREV:
|
2010-02-09 07:45:21 +08:00
|
|
|
|
player_play_file(play_list_prev());
|
2009-12-01 23:31:48 +08:00
|
|
|
|
next_step = PLAYER_STEP_NEXT;
|
|
|
|
|
break;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2010-02-25 00:05:37 +08:00
|
|
|
|
case PLAYER_REQUEST_FREEZE:
|
|
|
|
|
{
|
|
|
|
|
/* stop play */
|
|
|
|
|
if (player_is_playing() == RT_TRUE)
|
|
|
|
|
{
|
|
|
|
|
player_stop_req();
|
|
|
|
|
next_step = PLAYER_STEP_STOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* delay some tick */
|
|
|
|
|
rt_thread_delay(50);
|
|
|
|
|
|
|
|
|
|
/* show a modal view */
|
|
|
|
|
{
|
|
|
|
|
rtgui_view_t *view;
|
|
|
|
|
rtgui_label_t *label;
|
|
|
|
|
rtgui_rect_t rect = {0, 0, 150, 150}, container_rect;
|
|
|
|
|
|
|
|
|
|
rtgui_graphic_driver_get_default_rect(&container_rect);
|
|
|
|
|
/* set centre */
|
|
|
|
|
rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
|
view = rtgui_view_create("USB");
|
|
|
|
|
rtgui_workbench_add_view(workbench, view);
|
|
|
|
|
|
|
|
|
|
/* set container to window rect */
|
|
|
|
|
container_rect = rect;
|
|
|
|
|
|
|
|
|
|
rect.x1 = 0; rect.y1 = 0;
|
|
|
|
|
rect.x2 = 120; rect.y2 = 20;
|
|
|
|
|
label = rtgui_label_create("USB <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
|
|
|
|
rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
|
|
|
|
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
|
|
|
|
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
|
|
|
|
|
|
|
|
|
rtgui_view_show(view, RT_TRUE);
|
|
|
|
|
/* never reach hear */
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-01 23:31:48 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return RT_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtgui_view_event_handler(widget, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type == RTGUI_EVENT_KBD)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
2010-02-25 00:05:37 +08:00
|
|
|
|
if (((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME)
|
|
|
|
|
&& !RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
|
2009-12-01 23:31:48 +08:00
|
|
|
|
{
|
|
|
|
|
/* active home view */
|
|
|
|
|
if (workbench->current_view != home_view)
|
|
|
|
|
{
|
|
|
|
|
rtgui_view_show(home_view, RT_FALSE);
|
|
|
|
|
return RT_FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rtgui_workbench_event_handler(widget, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void player_entry(void* parameter)
|
|
|
|
|
{
|
|
|
|
|
rt_mq_t mq;
|
|
|
|
|
rtgui_rect_t rect;
|
|
|
|
|
|
|
|
|
|
mq = rt_mq_create("ply_ui", 256, 4, RT_IPC_FLAG_FIFO);
|
|
|
|
|
rtgui_thread_register(rt_thread_self(), mq);
|
|
|
|
|
|
|
|
|
|
/* create information timer */
|
2010-02-22 04:41:42 +08:00
|
|
|
|
info_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, info_timer_timeout, RT_NULL);
|
|
|
|
|
|
|
|
|
|
time_bg_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t *) time_bg_xpm, sizeof(time_bg_xpm), RT_TRUE);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
workbench = rtgui_workbench_create("main", "workbench");
|
|
|
|
|
if (workbench == RT_NULL) return;
|
|
|
|
|
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), player_workbench_event_handler);
|
|
|
|
|
|
|
|
|
|
/* add home view */
|
|
|
|
|
home_view = rtgui_view_create("Home");
|
|
|
|
|
rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);
|
|
|
|
|
|
|
|
|
|
rtgui_workbench_add_view(workbench, home_view);
|
|
|
|
|
/* this view can be focused */
|
|
|
|
|
RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
|
|
|
|
/* set widget focus */
|
|
|
|
|
rtgui_widget_focus(RTGUI_WIDGET(home_view));
|
|
|
|
|
|
|
|
|
|
rtgui_view_show(home_view, RT_FALSE);
|
|
|
|
|
|
|
|
|
|
/* add function view */
|
|
|
|
|
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
2010-02-18 07:56:49 +08:00
|
|
|
|
function_view = rtgui_list_view_create(function_list,
|
|
|
|
|
sizeof(function_list)/sizeof(struct rtgui_list_item),
|
2009-12-01 23:31:48 +08:00
|
|
|
|
&rect);
|
2010-02-18 07:56:49 +08:00
|
|
|
|
rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));
|
2009-12-01 23:31:48 +08:00
|
|
|
|
|
|
|
|
|
rtgui_workbench_event_loop(workbench);
|
|
|
|
|
|
|
|
|
|
rtgui_thread_deregister(rt_thread_self());
|
|
|
|
|
rt_mq_delete(mq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_notify_play(void)
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_command ecmd;
|
|
|
|
|
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
|
|
|
|
ecmd.type = RTGUI_CMD_USER_INT;
|
|
|
|
|
ecmd.command_id = PLAYER_REQUEST_PLAY_SINGLE_FILE;
|
|
|
|
|
|
|
|
|
|
rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_notify_stop()
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_command ecmd;
|
|
|
|
|
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
|
|
|
|
ecmd.type = RTGUI_CMD_USER_INT;
|
|
|
|
|
ecmd.command_id = PLAYER_REQUEST_STOP;
|
|
|
|
|
|
|
|
|
|
rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void player_ui_init()
|
|
|
|
|
{
|
|
|
|
|
player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL,
|
2010-02-18 07:56:49 +08:00
|
|
|
|
0x800, 25, 5);
|
2009-12-01 23:31:48 +08:00
|
|
|
|
if (player_ui_tid != RT_NULL)
|
|
|
|
|
rt_thread_startup(player_ui_tid);
|
|
|
|
|
}
|
2010-02-18 07:56:49 +08:00
|
|
|
|
|
2010-02-25 00:05:37 +08:00
|
|
|
|
void player_ui_freeze()
|
|
|
|
|
{
|
|
|
|
|
struct rtgui_event_command ecmd;
|
|
|
|
|
|
|
|
|
|
/* check whether UI starts. */
|
|
|
|
|
if (home_view == RT_NULL || workbench == RT_NULL) return;
|
|
|
|
|
|
|
|
|
|
RTGUI_EVENT_COMMAND_INIT(&ecmd);
|
|
|
|
|
ecmd.type = RTGUI_CMD_USER_INT;
|
|
|
|
|
ecmd.command_id = PLAYER_REQUEST_FREEZE;
|
|
|
|
|
|
|
|
|
|
rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd));
|
|
|
|
|
}
|
|
|
|
|
|