add wav file in UI.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@396 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
9dfd2fd177
commit
3025e3e8b3
@ -281,7 +281,9 @@ void mp3_get_info(const char* filename, struct tag_info* info)
|
|||||||
/* can't get sync word */
|
/* can't get sync word */
|
||||||
close(fd);
|
close(fd);
|
||||||
mp3_decoder_detach(decoder);
|
mp3_decoder_detach(decoder);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get frame information */
|
/* get frame information */
|
||||||
MP3GetNextFrameInfo(decoder, &frame_info, &id3buffer[sync_word]);
|
MP3GetNextFrameInfo(decoder, &frame_info, &id3buffer[sync_word]);
|
||||||
info->bit_rate = frame_info.bitrate;
|
info->bit_rate = frame_info.bitrate;
|
||||||
|
@ -91,6 +91,8 @@ rt_size_t net_buf_read(rt_uint8_t* buffer, rt_size_t length)
|
|||||||
/* buffer is not ready. */
|
/* buffer is not ready. */
|
||||||
_netbuf.is_wait_ready = RT_TRUE;
|
_netbuf.is_wait_ready = RT_TRUE;
|
||||||
rt_kprintf("wait ready, data len: %d, stat %d\n", data_length, _netbuf.stat);
|
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);
|
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);
|
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)
|
static void net_buf_do_job(struct net_buffer_job* job)
|
||||||
{
|
{
|
||||||
rt_uint32_t level;
|
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_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))
|
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)
|
if (_netbuf.is_wait_ready == RT_TRUE)
|
||||||
{
|
{
|
||||||
_netbuf.is_wait_ready = RT_FALSE;
|
_netbuf.is_wait_ready = RT_FALSE;
|
||||||
|
/* set buffer status to playing */
|
||||||
|
player_set_buffer_status(RT_FALSE);
|
||||||
rt_sem_release(_netbuf.wait_ready);
|
rt_sem_release(_netbuf.wait_ready);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ rt_bool_t player_is_playing()
|
|||||||
return is_playing;
|
return is_playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
void player_play_file(const char* fn)
|
void player_play_req(const char* fn)
|
||||||
{
|
{
|
||||||
struct player_request request;
|
struct player_request request;
|
||||||
request.type = PLAYER_REQUEST_PLAY_SINGLE_FILE;
|
request.type = PLAYER_REQUEST_PLAY_SINGLE_FILE;
|
||||||
@ -22,6 +22,7 @@ void player_play_file(const char* fn)
|
|||||||
/* send to message queue */
|
/* send to message queue */
|
||||||
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
|
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RT_USING_FINSH
|
#ifdef RT_USING_FINSH
|
||||||
#include <finsh.h>
|
#include <finsh.h>
|
||||||
static const char _fn[] = "/005.mp3";
|
static const char _fn[] = "/005.mp3";
|
||||||
@ -68,7 +69,18 @@ void player_thread(void* parameter)
|
|||||||
(strstr(request.fn, ".WAV") != RT_NULL))
|
(strstr(request.fn, ".WAV") != RT_NULL))
|
||||||
{
|
{
|
||||||
is_playing = RT_TRUE;
|
is_playing = RT_TRUE;
|
||||||
|
player_notify_play();
|
||||||
wav(request.fn);
|
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;
|
is_playing = RT_FALSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -31,7 +31,27 @@ static struct tag_info tinfo;
|
|||||||
|
|
||||||
void player_set_position(rt_uint32_t position)
|
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)
|
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));
|
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
|
||||||
|
|
||||||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
|
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_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
|
||||||
rtgui_dc_end_drawing(dc);
|
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;
|
char *pos, *next;
|
||||||
rt_uint32_t length;
|
rt_uint32_t length;
|
||||||
@ -132,7 +159,7 @@ static void player_update_tag_info(struct rtgui_dc* dc)
|
|||||||
else
|
else
|
||||||
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
|
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;
|
rect.x1 = rect.x2 - 64;
|
||||||
rt_snprintf(line, sizeof(line), "%02d:%02d:%02d",
|
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);
|
rtgui_dc_set_color(dc, saved);
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_mp3_file(const char* fn)
|
void player_play_file(const char* fn)
|
||||||
{
|
{
|
||||||
struct rtgui_dc* dc;
|
struct rtgui_dc* dc;
|
||||||
rtgui_color_t saved;
|
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 */
|
/* set player mode */
|
||||||
player_mode = PLAYER_PLAY_FILE;
|
player_mode = PLAYER_PLAY_FILE;
|
||||||
|
|
||||||
@ -185,7 +234,51 @@ void play_mp3_file(const char* fn)
|
|||||||
rtgui_view_show(home_view, RT_FALSE);
|
rtgui_view_show(home_view, RT_FALSE);
|
||||||
|
|
||||||
rt_kprintf("play file: %s\n", fn);
|
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)
|
void function_filelist(void* parameter)
|
||||||
@ -206,7 +299,9 @@ void function_filelist(void* parameter)
|
|||||||
view->items[view->current_item].name);
|
view->items[view->current_item].name);
|
||||||
|
|
||||||
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
|
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 */
|
/* clear old play list */
|
||||||
play_list_clear();
|
play_list_clear();
|
||||||
@ -214,7 +309,7 @@ void function_filelist(void* parameter)
|
|||||||
|
|
||||||
player_mode = PLAYER_PLAY_FILE;
|
player_mode = PLAYER_PLAY_FILE;
|
||||||
next_step = PLAYER_STEP_STOP;
|
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 ||
|
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
|
||||||
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;
|
player_mode = PLAYER_PLAY_FILE;
|
||||||
next_step = PLAYER_STEP_NEXT;
|
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 */
|
/* destroy view */
|
||||||
@ -298,7 +389,7 @@ void function_action(void* parameter)
|
|||||||
|
|
||||||
struct list_item function_list[] =
|
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_action, RT_NULL},
|
||||||
{"播放文件", RT_NULL, function_filelist, RT_NULL},
|
{"播放文件", RT_NULL, function_filelist, RT_NULL},
|
||||||
{"设备信息", RT_NULL, function_device, 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
|
else
|
||||||
rtgui_dc_draw_text(dc, tinfo.artist, &rect);
|
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;
|
rect.x1 = rect.x2 - 64;
|
||||||
rt_snprintf(line, sizeof(line), "%02d:%02d:%02d",
|
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))
|
if ((player_mode == PLAYER_STOP) && (play_list_items() > 0))
|
||||||
{
|
{
|
||||||
next_step = PLAYER_STEP_NEXT;
|
next_step = PLAYER_STEP_NEXT;
|
||||||
play_mp3_file(play_list_current_item());
|
player_play_file(play_list_current_item());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -546,13 +637,13 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
play_mp3_file(play_list_next());
|
player_play_file(play_list_next());
|
||||||
next_step = PLAYER_STEP_NEXT;
|
next_step = PLAYER_STEP_NEXT;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PLAYER_STEP_PREV:
|
case PLAYER_STEP_PREV:
|
||||||
play_mp3_file(play_list_prev());
|
player_play_file(play_list_prev());
|
||||||
next_step = PLAYER_STEP_NEXT;
|
next_step = PLAYER_STEP_NEXT;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user