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 <iostream>
|
||||
#include <esp_player_wrapper.h>
|
||||
#include "audio_setup.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
AudioPlayer::AudioPlayer() {
|
||||
playerHandle = setup_player(NULL, NULL);
|
||||
@@ -11,11 +12,21 @@ AudioPlayer::AudioPlayer() {
|
||||
esp_audio_vol_set(playerHandle, 50);
|
||||
}
|
||||
|
||||
void AudioPlayer::play(char* uri) {
|
||||
void AudioPlayer::play(std::string uri) {
|
||||
if (isLastUri(uri)) {
|
||||
esp_player_music_resume();
|
||||
} else {
|
||||
esp_player_music_stop();
|
||||
esp_player_sdcard_music_play(uri, 0);
|
||||
esp_player_sdcard_music_play(uri.c_str(), 0);
|
||||
std::cout << "Zeile 22 wurde ausgefuehrt." << "\n";
|
||||
lastUri = std::string(uri);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioPlayer::pause() {
|
||||
esp_player_music_pause();
|
||||
}
|
||||
|
||||
bool AudioPlayer::isLastUri(std::string uri) {
|
||||
return lastUri == uri;
|
||||
}
|
@@ -1,10 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class AudioPlayer {
|
||||
void* playerHandle;
|
||||
std::string lastUri;
|
||||
|
||||
public:
|
||||
AudioPlayer();
|
||||
void play(char* uri);
|
||||
void play(std::string uri);
|
||||
void pause();
|
||||
|
||||
private:
|
||||
bool isLastUri(std::string uri);
|
||||
};
|
@@ -5,13 +5,14 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
static const char* TAG = "TagPlayerControl";
|
||||
|
||||
TagPlayerControl::TagPlayerControl(AudioPlayer* player) {
|
||||
audioPlayer = player;
|
||||
TagPlayerControl::TagPlayerControl(std::shared_ptr<AudioPlayer> player)
|
||||
: audioPlayer(player) {
|
||||
}
|
||||
|
||||
void TagPlayerControl::onTagChanged(char* tagId) {
|
||||
@@ -55,7 +56,7 @@ void TagPlayerControl::playTag(char* tagId) {
|
||||
content.append(line);
|
||||
}
|
||||
|
||||
audioPlayer->play((char*)(content.c_str()));
|
||||
audioPlayer->play(content);
|
||||
|
||||
file.close();
|
||||
}
|
@@ -1,12 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "AudioPlayer.hpp"
|
||||
|
||||
class TagPlayerControl {
|
||||
AudioPlayer* audioPlayer;
|
||||
std::shared_ptr<AudioPlayer> audioPlayer;
|
||||
|
||||
public:
|
||||
TagPlayerControl(AudioPlayer* player);
|
||||
TagPlayerControl(std::shared_ptr<AudioPlayer> player);
|
||||
|
||||
void onTagChanged(char* tagId);
|
||||
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "TagPlayerControl.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
extern "C" {
|
||||
void app_main();
|
||||
@@ -16,6 +17,10 @@ Networking networking;
|
||||
WebInterface webInterface;
|
||||
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) {
|
||||
initArduino();
|
||||
|
||||
@@ -27,13 +32,13 @@ void app_main(void) {
|
||||
rfid.registerWebResources(&webInterface);
|
||||
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();
|
||||
|
||||
TagPlayerControl tagPlayerControl(&audioPlayer);
|
||||
|
||||
rfid.registerTagChangeCallback([&tagPlayerControl](char* tagId) {
|
||||
tagPlayerControl.onTagChanged(tagId);
|
||||
rfid.registerTagChangeCallback([tagPlayerControl](char* tagId) {
|
||||
tagPlayerControl->onTagChanged(tagId);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user