fix(audio): prefer cloud timeout prompts with local fallback
This commit is contained in:
@@ -24,7 +24,8 @@ static Mp3PlayConfigInfo mp3_configInfo;
|
||||
static unsigned char mp3_player_status = 0;
|
||||
QFILE *local_mp3_file_fd=NULL;
|
||||
|
||||
static int mp3_player_end_frame = 0;
|
||||
static int mp3_player_end_frame = 0;
|
||||
static int mp3_player_last_result = 0;
|
||||
|
||||
int current_sample_rate = 0;
|
||||
static audio_track_handle track_hd;
|
||||
@@ -278,9 +279,10 @@ u32 local_mp3_data_fetch(const char *uri, uint8_t *buffer, u32 length)
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
size_t url_mp3_data_fetch(const char *uri, uint8_t *buffer, size_t length)
|
||||
{
|
||||
int url_mp3_data_fetch(const char *uri, uint8_t *buffer, size_t length)
|
||||
{
|
||||
int resp_status = -1;
|
||||
int result = -1;
|
||||
uint32_t nw = length;
|
||||
uint32_t page_pos = 0;
|
||||
uint32_t content_length = 0;
|
||||
@@ -353,7 +355,10 @@ size_t url_mp3_data_fetch(const char *uri, uint8_t *buffer, size_t length)
|
||||
total_length += page_pos;
|
||||
}
|
||||
|
||||
printf("end read:%d, %d\n", total_length, session->content_length);
|
||||
printf("end read:%d, %d\n", total_length, session->content_length);
|
||||
if(total_length == session->content_length){
|
||||
result = 0;
|
||||
}
|
||||
|
||||
__exit:
|
||||
|
||||
@@ -363,13 +368,13 @@ __exit:
|
||||
session = NULL;
|
||||
}
|
||||
|
||||
if(total_length<content_length){
|
||||
total_length = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
if(result != 0 || total_length < content_length){
|
||||
total_length = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct mp3_decoder* aofei_mp3_decoder = NULL;
|
||||
@@ -389,24 +394,45 @@ int aofei_mp3_player_init(void)
|
||||
|
||||
void aofei_mp3_player(char *file_name)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t *mp3_buff = malloc(100*1024);
|
||||
|
||||
memset(mp3_buff, 0, 100*1024);
|
||||
//直接下载到一个100k的buffer
|
||||
if(strstr(file_name, "http:")){//播放url
|
||||
ret = url_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
int ret = 0;
|
||||
uint8_t *mp3_buff = NULL;
|
||||
|
||||
mp3_player_last_result = -1;
|
||||
if(file_name == NULL){
|
||||
printf("mp3 player file name is null\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
mp3_buff = malloc(100*1024);
|
||||
if(mp3_buff == NULL){
|
||||
printf("mp3 player buffer malloc failed\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(mp3_buff, 0, 100*1024);
|
||||
//直接下载到一个100k的buffer
|
||||
if(strncmp(file_name, "http://", strlen("http://")) == 0 ||
|
||||
strncmp(file_name, "https://", strlen("https://")) == 0){//播放url
|
||||
ret = url_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
}else if(strstr(file_name, "test.mp3")){//播放本地音频
|
||||
total_length = test_data_size;
|
||||
memcpy(mp3_buff, test_data, total_length);
|
||||
}else{//播放本地音频
|
||||
total_length = local_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
}
|
||||
}else{//播放本地音频
|
||||
total_length = local_mp3_data_fetch(file_name, mp3_buff, 100*1024);
|
||||
}
|
||||
|
||||
if(ret < 0 || total_length == 0){
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
mp3_player_end_frame = 0;
|
||||
|
||||
|
||||
if(aofei_mp3_player_init()==-1)return;
|
||||
if(aofei_mp3_player_init()==-1){
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
if(ret>=0){
|
||||
aofei_mp3_decoder->read_ptr = mp3_buff;
|
||||
@@ -457,6 +483,7 @@ void aofei_mp3_player(char *file_name)
|
||||
app_codec_pa_close();
|
||||
}
|
||||
|
||||
__exit:
|
||||
if(aofei_mp3_decoder!=NULL){
|
||||
mp3_decoder_delete(aofei_mp3_decoder);
|
||||
aofei_mp3_decoder = NULL;
|
||||
@@ -477,10 +504,17 @@ void aofei_mp3_player(char *file_name)
|
||||
mp3_buff = NULL;
|
||||
}
|
||||
|
||||
total_length = 0;
|
||||
mp3_player_end_frame = 0;
|
||||
mp3_player_status = 0;
|
||||
}
|
||||
total_length = 0;
|
||||
mp3_player_end_frame = 0;
|
||||
mp3_player_status = 0;
|
||||
mp3_player_last_result = ret;
|
||||
}
|
||||
|
||||
/* 播放调用是同步的,队列线程可在返回后读取本次结果决定是否使用本地兜底。 */
|
||||
int aofei_mp3_player_get_result(void)
|
||||
{
|
||||
return mp3_player_last_result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user