mirror of
https://github.com/sweidac/kidsbox.git
synced 2025-07-27 19:31:54 +02:00
Implements pause/resume for one file.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
#include "AudioPlayer.hpp"
|
#include "AudioPlayer.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <esp_player_wrapper.h>
|
#include <esp_player_wrapper.h>
|
||||||
#include "audio_setup.h"
|
#include "audio_setup.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
AudioPlayer::AudioPlayer() {
|
AudioPlayer::AudioPlayer() {
|
||||||
playerHandle = setup_player(NULL, NULL);
|
playerHandle = setup_player(NULL, NULL);
|
||||||
@@ -11,11 +12,21 @@ AudioPlayer::AudioPlayer() {
|
|||||||
esp_audio_vol_set(playerHandle, 50);
|
esp_audio_vol_set(playerHandle, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioPlayer::play(char* uri) {
|
void AudioPlayer::play(std::string uri) {
|
||||||
esp_player_music_stop();
|
if (isLastUri(uri)) {
|
||||||
esp_player_sdcard_music_play(uri, 0);
|
esp_player_music_resume();
|
||||||
|
} else {
|
||||||
|
esp_player_music_stop();
|
||||||
|
esp_player_sdcard_music_play(uri.c_str(), 0);
|
||||||
|
std::cout << "Zeile 22 wurde ausgefuehrt." << "\n";
|
||||||
|
lastUri = std::string(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioPlayer::pause() {
|
void AudioPlayer::pause() {
|
||||||
esp_player_music_pause();
|
esp_player_music_pause();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AudioPlayer::isLastUri(std::string uri) {
|
||||||
|
return lastUri == uri;
|
||||||
}
|
}
|
@@ -1,10 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class AudioPlayer {
|
class AudioPlayer {
|
||||||
void* playerHandle;
|
void* playerHandle;
|
||||||
|
std::string lastUri;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AudioPlayer();
|
AudioPlayer();
|
||||||
void play(char* uri);
|
void play(std::string uri);
|
||||||
void pause();
|
void pause();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool isLastUri(std::string uri);
|
||||||
};
|
};
|
@@ -5,13 +5,14 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <esp_log.h>
|
#include <esp_log.h>
|
||||||
|
|
||||||
static const char* TAG = "TagPlayerControl";
|
static const char* TAG = "TagPlayerControl";
|
||||||
|
|
||||||
TagPlayerControl::TagPlayerControl(AudioPlayer* player) {
|
TagPlayerControl::TagPlayerControl(std::shared_ptr<AudioPlayer> player)
|
||||||
audioPlayer = player;
|
: audioPlayer(player) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TagPlayerControl::onTagChanged(char* tagId) {
|
void TagPlayerControl::onTagChanged(char* tagId) {
|
||||||
@@ -55,7 +56,7 @@ void TagPlayerControl::playTag(char* tagId) {
|
|||||||
content.append(line);
|
content.append(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
audioPlayer->play((char*)(content.c_str()));
|
audioPlayer->play(content);
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "AudioPlayer.hpp"
|
#include "AudioPlayer.hpp"
|
||||||
|
|
||||||
class TagPlayerControl {
|
class TagPlayerControl {
|
||||||
AudioPlayer* audioPlayer;
|
std::shared_ptr<AudioPlayer> audioPlayer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TagPlayerControl(AudioPlayer* player);
|
TagPlayerControl(std::shared_ptr<AudioPlayer> player);
|
||||||
|
|
||||||
void onTagChanged(char* tagId);
|
void onTagChanged(char* tagId);
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
#include "TagPlayerControl.hpp"
|
#include "TagPlayerControl.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void app_main();
|
void app_main();
|
||||||
@@ -16,24 +17,28 @@ Networking networking;
|
|||||||
WebInterface webInterface;
|
WebInterface webInterface;
|
||||||
RFIDInterface rfid;
|
RFIDInterface rfid;
|
||||||
|
|
||||||
|
std::shared_ptr<AudioPlayer> audioPlayer; // initialize here, because the ctor does init stuff that fails when executed before `app_main()`
|
||||||
|
|
||||||
|
std::shared_ptr<TagPlayerControl> tagPlayerControl;
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
initArduino();
|
initArduino();
|
||||||
|
|
||||||
webInterface.initSD();
|
webInterface.initSD();
|
||||||
|
|
||||||
/* networking.connectWifi();
|
/* networking.connectWifi();
|
||||||
webInterface.start();
|
webInterface.start();
|
||||||
|
|
||||||
rfid.registerWebResources(&webInterface);
|
rfid.registerWebResources(&webInterface);
|
||||||
webInterface.finishResourceRegistrations();
|
webInterface.finishResourceRegistrations();
|
||||||
*/
|
*/
|
||||||
AudioPlayer audioPlayer; // initialize here, because the ctor does init stuff that fails when executed before `app_main()`
|
|
||||||
|
audioPlayer = std::make_shared<AudioPlayer>();
|
||||||
|
tagPlayerControl = std::make_shared<TagPlayerControl>(audioPlayer);
|
||||||
|
|
||||||
rfid.start();
|
rfid.start();
|
||||||
|
|
||||||
TagPlayerControl tagPlayerControl(&audioPlayer);
|
|
||||||
|
|
||||||
rfid.registerTagChangeCallback([&tagPlayerControl](char* tagId) {
|
rfid.registerTagChangeCallback([tagPlayerControl](char* tagId) {
|
||||||
tagPlayerControl.onTagChanged(tagId);
|
tagPlayerControl->onTagChanged(tagId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user