[AUDIO] add close mp3 file playing
Change-Id: I2345b112e9143f0685dad6997706757cc26cbdbf
diff --git a/mbtk/mbtk_lib/src/mbtk_audio_alsa.c b/mbtk/mbtk_lib/src/mbtk_audio_alsa.c
index d654c6a..6d85edc 100755
--- a/mbtk/mbtk_lib/src/mbtk_audio_alsa.c
+++ b/mbtk/mbtk_lib/src/mbtk_audio_alsa.c
@@ -220,6 +220,16 @@
pthread_mutex_unlock(&pcxt->_cond_mutex);
}
+
+int mbtk_audio_get_status(void* hdl)
+{
+ struct mopen_audio_t *pcxt = (struct mopen_audio_t *)hdl;
+ if (NULL == hdl || NULL == internal_hdl)
+ return 0;
+
+ return pcxt->state;
+}
+
static void* mbtk_record_pthread(void* hdl)
{
struct mopen_audio_t *pcxt = (struct mopen_audio_t *)hdl;
diff --git a/mbtk/mbtk_lib/src/mbtk_mp3_to_wav.c b/mbtk/mbtk_lib/src/mbtk_mp3_to_wav.c
index 73a4e86..0ec8a17 100755
--- a/mbtk/mbtk_lib/src/mbtk_mp3_to_wav.c
+++ b/mbtk/mbtk_lib/src/mbtk_mp3_to_wav.c
@@ -1,3 +1,4 @@
+#include "mbtk_audio.h"
#include "audio_if_types.h"
#include "audio_if_ubus.h"
#include "audio_if_parameter.h"
@@ -39,6 +40,7 @@
extern int mbtk_audio_play_stream_old(void *dev_hdl, const void *pData, int len);
+extern int mbtk_audio_get_status(void* hdl);
#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
@@ -272,6 +274,7 @@
int got_frame;
int index =0;
int i =0;
+ int audio_status =0;
AVPacket *packet = av_mallocz(sizeof(AVPacket));
//AVFrame *frame = av_frame_alloc();
AVFrame *frame = avcodec_alloc_frame();
@@ -307,7 +310,9 @@
return -1;
}
- while(av_read_frame(is->pFormatCtx, packet) >= 0) //1.2 循环读取mp3文件中的数据帧
+ audio_status = mbtk_audio_get_status((void *)hdl);
+
+ while(av_read_frame(is->pFormatCtx, packet) >= 0 && ((audio_status==AUDIO_OPEN)|| (audio_status==AUDIO_RUNNING))) //1.2 循环读取mp3文件中的数据帧
{
if(packet->stream_index != is->sndindex)
continue;