电子学生证·播放MP3
播放 MP3 文件有两种方式,一种是MP3文件,另一种是MP3流
播放本地MP3文件
播放本地文件
// 回调函数,用于监控播放状态,例如开始播放,播放完成,停止播放等等
static int sw_file_play_callback(char *p_data, int len, int res) //p_data and len is not usd
{
sw_debug_trace("sw_file_play_callback res = %d\n", res);
return 0;
}
sw_set_audio_path_earphone();
sw_set_volume(10);
sw_play_file_init((cb_on_player)sw_file_play_callback);
sw_play_file_start(play_mp3_option, "netkiller.mp3");
sw_sleep(10000);
sw_debug_trace(" mp3 test end \n");
sw_play_file_stop();
播放网络文件
首先需要把文件下载下来,保存到本地,然后再播放
static char topic[128] = {0};
static char imei[16] = {0};
int chat_audio_play_callback(char *p_data, int len, enum_aud_player_state state)
{
if (state == AUD_PLAYER_START)
{
sw_usb_debug_trace("chat_audio_play_callback play start\r\n");
}
else if (state == AUD_PLAYER_MOREDATA)
{
sw_usb_debug_trace("chat_audio_play_callback play stream\r\n");
}
else if (state == AUD_PLAYER_FINISHED)
{
sw_usb_debug_trace("chat_audio_play_callback play stop\r\n");
if (sw_fs_check(QUESTION_FILE) == 0)
{
sw_fs_remove(QUESTION_FILE);
}
}
else
{
sw_usb_debug_trace("chat_audio_play_callback state = %d, len=%d\r\n", state,