diff options
| author | bernard.xiong <[email protected]> | 2010-02-08 23:45:21 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-02-08 23:45:21 +0000 |
| commit | 3025e3e8b37cefc15d689c2d5ab9dbc4944645fb (patch) | |
| tree | ff60f8c93bc7a53e1766a0be6c3894124b20f761 | |
| parent | 9dfd2fd177d2ee2d566124710faf41a5a3b9c952 (diff) | |
add wav file in UI.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@396 bbd45198-f89e-11dd-88c7-29a3b14d5316
| -rw-r--r-- | bsp/stm32_radio/mp3.c | 2 | ||||
| -rw-r--r-- | bsp/stm32_radio/netbuffer.c | 11 | ||||
| -rw-r--r-- | bsp/stm32_radio/player_bg.c | 14 | ||||
| -rw-r--r-- | bsp/stm32_radio/player_ui.c | 137 |
4 files changed, 138 insertions, 26 deletions
diff --git a/bsp/stm32_radio/mp3.c b/bsp/stm32_radio/mp3.c index e8ad535bd0..c269a16509 100644 --- a/bsp/stm32_radio/mp3.c +++ b/bsp/stm32_radio/mp3.c @@ -281,7 +281,9 @@ void mp3_get_info(const char* filename, struct tag_info* info) /* can't get sync word */
close(fd);
mp3_decoder_detach(decoder);
+ return;
}
+
/* get frame information */
MP3GetNextFrameInfo(decoder, &frame_info, &id3buffer[sync_word]);
info->bit_rate = frame_info.bitrate;
diff --git a/bsp/stm32_radio/netbuffer.c b/bsp/stm32_radio/netbuffer.c index 544958c557..aa0198445d 100644 --- a/bsp/stm32_radio/netbuffer.c +++ b/bsp/stm32_radio/netbuffer.c @@ -91,6 +91,8 @@ rt_size_t net_buf_read(rt_uint8_t* buffer, rt_size_t length) /* buffer is not ready. */
_netbuf.is_wait_ready = RT_TRUE;
rt_kprintf("wait ready, data len: %d, stat %d\n", data_length, _netbuf.stat);
+ /* set buffer status to buffering */
+ player_set_buffer_status(RT_TRUE);
rt_sem_take(_netbuf.wait_ready, RT_WAITING_FOREVER);
}
@@ -192,7 +194,7 @@ static void net_buf_do_stop(struct net_buffer_job* job) rt_kprintf("job done, stat %d\n", _netbuf.stat);
}
-#define NETBUF_BLOCK_SIZE 1024
+#define NETBUF_BLOCK_SIZE 4096
static void net_buf_do_job(struct net_buffer_job* job)
{
rt_uint32_t level;
@@ -265,7 +267,10 @@ static void net_buf_do_job(struct net_buffer_job* job) rt_hw_interrupt_enable(level);
}
- // rt_kprintf("buffering ... %d %c\n", (data_length * 100) / _netbuf.size, '%');
+ rt_kprintf("buffering ... %d %c\n", (data_length * 100) / _netbuf.size, '%');
+
+ /* set buffer position */
+ player_set_position(data_length);
if ((_netbuf.stat == NETBUF_STAT_BUFFERING) && (data_length >= _netbuf.ready_wm))
{
@@ -277,6 +282,8 @@ static void net_buf_do_job(struct net_buffer_job* job) if (_netbuf.is_wait_ready == RT_TRUE)
{
_netbuf.is_wait_ready = RT_FALSE;
+ /* set buffer status to playing */
+ player_set_buffer_status(RT_FALSE);
rt_sem_release(_netbuf.wait_ready);
}
}
diff --git a/bsp/stm32_radio/player_bg.c b/bsp/stm32_radio/player_bg.c index 905fb15682..353ed0ec0e 100644 --- a/bsp/stm32_radio/player_bg.c +++ b/bsp/stm32_radio/player_bg.c @@ -13,7 +13,7 @@ rt_bool_t player_is_playing() return is_playing;
}
-void player_play_file(const char* fn)
+void player_play_req(const char* fn)
{
struct player_request request;
request.type = PLAYER_REQUEST_PLAY_SINGLE_FILE;
@@ -22,6 +22,7 @@ void player_play_file(const char* fn) /* send to message queue */
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
}
+
#ifdef RT_USING_FINSH
#include <finsh.h>
static const char _fn[] = "/005.mp3";
@@ -68,7 +69,18 @@ void player_thread(void* parameter) (strstr(request.fn, ".WAV") != RT_NULL))
{
is_playing = RT_TRUE;
+ player_notify_play();
wav(request.fn);
+ player_notify_stop();
+ is_playing = RT_FALSE;
+ }
+ else if ((strstr(request.fn, "http://") == request.fn ||
+ (strstr(request.fn, "HTTP://") == request.fn )))
+ {
+ is_playing = RT_TRUE;
+ player_notify_play();
+ ice_mp3(request.fn);
+ player_notify_stop();
is_playing = RT_FALSE;
}
break;
diff --git a/bsp/stm32_radio/player_ui.c b/bsp/stm32_radio/player_ui.c index 7487175773..f6b12ec6e6 100644 --- a/bsp/stm32_radio/player_ui.c +++ b/bsp/stm32_radio/player_ui.c @@ -31,7 +31,27 @@ static struct tag_info tinfo; void player_set_position(rt_uint32_t position)
{
- tinfo.position = position / (tinfo.bit_rate / 8);
+ 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, "������...", 40);
+ else
+ strncpy(tinfo.artist, "������...", 40);
}
void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
@@ -45,13 +65,20 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter) saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
- rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212) / tinfo.duration, 75);
+ rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212)/ tinfo.duration,
+ 75);
+ if (player_mode == PLAYER_PLAY_RADIO)
+ {
+ RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
+ rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75);
+ }
+
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
rtgui_dc_end_drawing(dc);
}
-rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
+static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
{
char *pos, *next;
rt_uint32_t length;
@@ -132,7 +159,7 @@ static void player_update_tag_info(struct rtgui_dc* dc) else
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
- if ((tinfo.duration != 0) && player_mode != PLAYER_STOP)
+ if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE)
{
rect.x1 = rect.x2 - 64;
rt_snprintf(line, sizeof(line), "%02d:%02d:%02d",
@@ -143,16 +170,38 @@ static void player_update_tag_info(struct rtgui_dc* dc) rtgui_dc_set_color(dc, saved);
}
-void play_mp3_file(const char* fn)
+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), "<δ֪������>");
+ }
+ else
+ {
+ /* wav file */
+ rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
+ rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav����>");
+
+ tinfo.duration = 0;
+ }
- /* get music tag information */
- mp3_get_info(fn, &tinfo);
- if (tinfo.title[0] == '\0')
- rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
-
/* set player mode */
player_mode = PLAYER_PLAY_FILE;
@@ -185,7 +234,51 @@ void play_mp3_file(const char* fn) rtgui_view_show(home_view, RT_FALSE);
rt_kprintf("play file: %s\n", fn);
- player_play_file(fn);
+ player_play_req(fn);
+}
+
+void player_play_url(const char* url)
+{
+ struct rtgui_dc* dc;
+
+ /* set music tag information */
+ strncpy(tinfo.title, "�����̨", 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);
+
+ rt_kprintf("play radio url: %s\n", url);
+ player_play_req(url);
+}
+
+void function_play_radio(void* parameter)
+{
+ next_step = PLAYER_STEP_STOP;
+ player_play_url("http://syragon.com:8000/ices");
}
void function_filelist(void* parameter)
@@ -206,7 +299,9 @@ void function_filelist(void* parameter) view->items[view->current_item].name);
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
- strstr(view->items[view->current_item].name , ".MP3") != RT_NULL)
+ 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)
{
/* clear old play list */
play_list_clear();
@@ -214,7 +309,7 @@ void function_filelist(void* parameter) player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_STOP;
- play_mp3_file(play_list_start());
+ player_play_file(play_list_start());
}
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
strstr(view->items[view->current_item].name , ".M3U") != RT_NULL)
@@ -253,14 +348,10 @@ void function_filelist(void* parameter) {
player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_NEXT;
- play_mp3_file(play_list_start());
+ player_play_file(play_list_start());
}
}
}
- else if (strstr(view->items[view->current_item].name , ".wav") != RT_NULL ||
- strstr(view->items[view->current_item].name , ".WAV") != RT_NULL)
- {
- }
}
/* destroy view */
@@ -298,7 +389,7 @@ void function_action(void* parameter) struct list_item function_list[] =
{
- {"ѡ���̨", RT_NULL, function_action, RT_NULL},
+ {"ѡ���̨", RT_NULL, function_play_radio, RT_NULL},
{"���µ�̨", RT_NULL, function_action, RT_NULL},
{"�����ļ�", RT_NULL, function_filelist, RT_NULL},
{"�豸��Ϣ", RT_NULL, function_device, RT_NULL},
@@ -375,7 +466,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg else
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
- if (tinfo.duration != 0)
+ if ((tinfo.duration != 0) && (player_mode == PLAYER_PLAY_FILE))
{
rect.x1 = rect.x2 - 64;
rt_snprintf(line, sizeof(line), "%02d:%02d:%02d",
@@ -451,7 +542,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg if ((player_mode == PLAYER_STOP) && (play_list_items() > 0))
{
next_step = PLAYER_STEP_NEXT;
- play_mp3_file(play_list_current_item());
+ player_play_file(play_list_current_item());
}
}
break;
@@ -546,13 +637,13 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg }
else
{
- play_mp3_file(play_list_next());
+ player_play_file(play_list_next());
next_step = PLAYER_STEP_NEXT;
}
break;
case PLAYER_STEP_PREV:
- play_mp3_file(play_list_prev());
+ player_play_file(play_list_prev());
next_step = PLAYER_STEP_NEXT;
break;
};
|
