567
社区成员




FS_HANDLE g_file_handle;
#define buf_size (256 * 1024)
U8 audio_data[buf_size];
void stop_play_mp3_string(void)
{
mdi_audio_stop_all();
FS_Close(g_file_handle);
GoBackHistory();
}
/* continue play mp3 string */
void play_mp3_string_continue(mdi_result result)
{
UINT len = 0;
if (FS_NO_ERROR != FS_Read(g_file_handle, audio_data, buf_size, &len))
{
DisplayPopup((U8*)L"Read File Failed", IMG_GLOBAL_OK, 1, 5000, 13);
return;
}
if (len <= 0)
{
return;
}
else
{
mdi_audio_play_string_with_vol_path_non_block(audio_data, buf_size,
MDI_FORMAT_DAF, DEVICE_AUDIO_PLAY_ONCE, NULL, play_mp3_string_continue,
(U8)6, MDI_DEVICE_SPEAKER_BOTH);
}
}
/* start to play mp3 string */
void start_play_mp3_string(void)
{
UINT len;
if ((g_file_handle = FS_Open(L"D:\\text\\a.mp3", FS_READ_ONLY)) < 0)
{
DisplayPopup((U8*)L"Open File Failed", IMG_GLOBAL_OK, 1, 5000, 13);
return;
}
if (FS_NO_ERROR != FS_Read(g_file_handle, audio_data, buf_size, &len))
{
DisplayPopup((U8*)L"Read File Failed", IMG_GLOBAL_OK, 1, 5000, 13);
FS_Close(g_file_handle);
return;
}
mdi_audio_play_string_with_vol_path_non_block(audio_data, buf_size,
MDI_FORMAT_DAF, DEVICE_AUDIO_PLAY_ONCE, NULL, play_mp3_string_continue,
(U8)6, MDI_DEVICE_SPEAKER_BOTH);
}
void audio_play_entry(void)
{
EntryNewScreen(MAIN_MENU_SCREENID, NULL, audio_play_entry, NULL);
clear_screen();
gui_set_text_color(UI_COLOR_RED);
gui_move_text_cursor(50, 50);
gui_print_text(L"Audio Player");
gui_move_text_cursor(25, 100);
gui_print_text(L"Press left key to play");
gui_move_text_cursor(10, 120);
gui_print_text(L"Press right key to pause/resume");
gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
// 左键
SetKeyHandler(start_play_mp3_string, KEY_LSK, KEY_EVENT_DOWN);
// 右键
SetKeyHandler(stop_play_mp3_string, KEY_RSK, KEY_EVENT_DOWN);
}