我正在尝试在Sony Spresense上重复播放音频文件。我已经测试了Sony提供的示例草图,它们可以很好地播放音频文件。但是如果我想要重放这个文件,我会得到错误。不幸的是,所有的草图只播放他们的文件一次...
为了简单起见,我缩小了源代码。
#include <Audio.h>
#include <SDHCI.h>
static void audioErrorCallback(const ErrorAttentionParam *atprm);
bool initializeSound();
SDClass theSD;
AudioClass *theAudio;
File soundFile;
bool soundFinished;
void setup() {
Serial.begin(115200);
while (!Serial);
initializeSound();
soundFinished = true;
}
void loop() {
if (!soundFinished) {
int err = theAudio->writeFrames(AudioClass::Player0, soundFile);
if (err == AUDIOLIB_ECODE_FILEEND) {
soundFinished = true;
stopPlay();
}
} else {
Serial.println("Sleep");
delay(3000);
soundFinished = false;
startPlay();
}
usleep(40000);
}
static void audioErrorCallback(const ErrorAttentionParam *atprm) {
if (atprm->error_code >= AS_ATTENTION_CODE_WARNING)
{
Serial.println("Error!");
}
}
bool initializeSound() {
theAudio = AudioClass::getInstance();
theAudio->begin(audioErrorCallback);
theAudio->setRenderingClockMode(AS_CLKMODE_NORMAL);
theAudio->setPlayerMode(AS_SETPLAYER_OUTPUTDEVICE_SPHP, AS_SP_DRV_MODE_LINEOUT);
theAudio->initPlayer(AudioClass::Player0, AS_CODECTYPE_MP3, "/mnt/sd0/BIN", AS_SAMPLINGRATE_AUTO, AS_CHANNEL_STEREO);
soundFile = theSD.open("audioFile.mp3");
theAudio->setVolume(-160);
return true;
}
void startPlay() {
theAudio->writeFrames(AudioClass::Player0, soundFile);
theAudio->startPlayer(AudioClass::Player0);
}
void stopPlay() {
theAudio->stopPlayer(AudioClass::Player0);
// soundFile.close();
}音频文件第一次播放时没有问题。之后,我总是收到以下错误:
Attention: module[5] attention id[2]/code[6] (objects/media_player/player_input_device_handler.cpp L220)
Error!
ERROR: Command (0x22) fails. Result code(0xf1) Module id(0x5) Error code(0x2f) Error subcode(0x0)
ERROR: Command (0x23) fails. Result code(0xf1) Module id(0x5) Error code(0x1)遗漏了什么?有什么想法吗?
发布于 2020-05-23 13:16:39
我也遇到过类似的问题,我可以通过关闭最后的File并在循环()的开头创建一个新的File来修复它,而不是在setup()函数中。
https://stackoverflow.com/questions/54305160
复制相似问题