567
社区成员




FS_HANDLE g_file_handle;
U8 audio_data[1024 * 64];
UINT len;
#define buf_size sizeof(audio_data)
void play_mp3_frame_continue(mdi_result result)
{
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 < buf_size)
{
mdi_audio_play_string_with_vol_path(audio_data, buf_size, MDI_FORMAT_DAF, DEVICE_AUDIO_PLAY_ONCE, NULL, NULL, (U8)6, MDI_DEVICE_SPEAKER_BOTH);
FS_Close(g_file_handle);
return;
}
else
{
mdi_audio_play_string_with_vol_path(audio_data, buf_size, MDI_FORMAT_DAF, DEVICE_AUDIO_PLAY_ONCE, NULL, play_mp3_frame_continue, (U8)6, MDI_DEVICE_SPEAKER_BOTH);
}
}
void play_mp3_frame(void)
{
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(audio_data, buf_size, MDI_FORMAT_DAF, DEVICE_AUDIO_PLAY_ONCE, NULL, play_mp3_frame_continue, (U8)6, MDI_DEVICE_SPEAKER_BOTH);
if (len < buf_size)
{
return;
}
}
void exit_play_mp3_frame(void)
{
mdi_audio_stop_string();
FS_Close(g_file_handle);
GoBackHistory();
}
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(25, 120);
gui_print_text(L"Press right key to stop");
gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
SetKeyHandler(exit_play_mp3_frame, KEY_RSK, KEY_EVENT_UP);
SetKeyHandler(play_mp3_frame, KEY_LSK, KEY_EVENT_UP);
}