123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #include "player_bg.h"
- #include "player_ui.h"
- #include "mp3.h"
- #include <string.h>
- rt_bool_t is_playing = RT_FALSE;
- static rt_mq_t player_thread_mq;
- static struct rt_thread player_thread_tid;
- static rt_uint8_t player_thread_stack[0x400];
- rt_bool_t player_is_playing()
- {
- return is_playing;
- }
- void player_play_req(const char* fn)
- {
- struct player_request request;
- request.type = PLAYER_REQUEST_PLAY_SINGLE_FILE;
- strncpy(request.fn, fn, sizeof(request.fn));
- /* send to message queue */
- rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
- }
- void player_stop_req()
- {
- is_playing = RT_FALSE;
- }
- void player_thread(void* parameter)
- {
- rt_err_t result;
- struct player_request request;
- while(1)
- {
- /* get request from message queue */
- result = rt_mq_recv(player_thread_mq, (void*)&request,
- sizeof(struct player_request), RT_WAITING_FOREVER);
- if (result == RT_EOK)
- {
- switch (request.type)
- {
- case PLAYER_REQUEST_PLAY_SINGLE_FILE:
- if ((strstr(request.fn, ".mp3") != RT_NULL) ||
- (strstr(request.fn, ".MP3") != RT_NULL))
- {
- is_playing = RT_TRUE;
- player_notify_play();
- /* get music tag information */
- mp3(request.fn);
- player_notify_stop();
- is_playing = RT_FALSE;
- }
- else if ((strstr(request.fn, ".wav") != RT_NULL) ||
- (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);
- /* notfiy net buffer worker to stop */
- net_buf_stop_job();
- player_notify_stop();
- is_playing = RT_FALSE;
- }
- break;
- }
- }
- }
- }
- void player_init()
- {
- rt_err_t result;
- /* create player thread */
- player_thread_mq = rt_mq_create("player", sizeof(struct player_request),
- 8, RT_IPC_FLAG_FIFO);
- RT_ASSERT(player_thread_mq != RT_NULL);
- result = rt_thread_init(&player_thread_tid, "ply_bg", player_thread, RT_NULL,
- player_thread_stack, sizeof(player_thread_stack),
- 20, 5);
- if (result != RT_EOK) rt_kprintf("player thread init failed\n");
- else
- {
- rt_thread_startup(&player_thread_tid);
- player_ui_init();
- }
- }
|