mirror of
https://github.com/sweidac/kidsbox.git
synced 2025-07-27 19:31:54 +02:00
Wip.
This commit is contained in:
@@ -12,12 +12,12 @@ AudioPlayer::AudioPlayer() {
|
||||
esp_audio_vol_set(playerHandle, 50);
|
||||
}
|
||||
|
||||
void AudioPlayer::play(std::string uri) {
|
||||
void AudioPlayer::play(std::string uri, int position = 0) {
|
||||
if (isLastUri(uri)) {
|
||||
esp_player_music_resume();
|
||||
} else {
|
||||
esp_player_music_stop();
|
||||
esp_player_sdcard_music_play(uri.c_str(), 0);
|
||||
esp_player_sdcard_music_play(uri.c_str(), position);
|
||||
lastUri = std::string(uri);
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,12 @@ void AudioPlayer::pause() {
|
||||
|
||||
bool AudioPlayer::isLastUri(std::string uri) {
|
||||
return lastUri == uri;
|
||||
}
|
||||
|
||||
int AudioPlayer::getPosition() {
|
||||
int position;
|
||||
|
||||
esp_player_pos_get(&position);
|
||||
|
||||
return position;
|
||||
}
|
@@ -8,8 +8,10 @@ class AudioPlayer {
|
||||
|
||||
public:
|
||||
AudioPlayer();
|
||||
void play(std::string uri);
|
||||
|
||||
void play(std::string uri, int position);
|
||||
void pause();
|
||||
int getPosition();
|
||||
|
||||
private:
|
||||
bool isLastUri(std::string uri);
|
||||
|
@@ -21,6 +21,8 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
Tag::Tag() {}
|
||||
|
||||
Tag::Tag(char* tagId): Tag(std::string(tagId)) {
|
||||
|
||||
}
|
||||
@@ -29,6 +31,15 @@ Tag::Tag(std::string tagId): tagId(tagId) {
|
||||
this->playlist = std::vector<std::string>();
|
||||
}
|
||||
|
||||
void Tag::setCurrentPosition(uint32_t fileIndex, uint32_t position) {
|
||||
this->currentFileIndex = fileIndex;
|
||||
this->currentFilePosition = position;
|
||||
}
|
||||
|
||||
int Tag::getCurrentPosition() {
|
||||
return this->currentFilePosition;
|
||||
}
|
||||
|
||||
std::string Tag::getNextLink() {
|
||||
return this->playlist.at(this->currentFileIndex);
|
||||
}
|
||||
@@ -90,6 +101,8 @@ void Tag::read() {
|
||||
void Tag::write() {
|
||||
std::string contents = createFileContents();
|
||||
|
||||
std::cout << contents << std::endl;
|
||||
|
||||
std::string filePath = getFilePath();
|
||||
|
||||
std::ofstream file(filePath);
|
||||
|
@@ -11,12 +11,15 @@ class Tag {
|
||||
uint32_t currentFilePosition{0};
|
||||
|
||||
public:
|
||||
Tag();
|
||||
Tag(std::string tagId);
|
||||
Tag(char* tagId);
|
||||
void read();
|
||||
void write();
|
||||
bool isLinked();
|
||||
std::string getNextLink();
|
||||
void setCurrentPosition(uint32_t fileIndex, uint32_t position);
|
||||
int getCurrentPosition();
|
||||
|
||||
private:
|
||||
std::string createFileContents();
|
||||
|
@@ -20,16 +20,22 @@ void TagPlayerControl::onTagChanged(char* tagId) {
|
||||
if (tagId == NULL) {
|
||||
// tag has been removed. stop playback
|
||||
audioPlayer->pause();
|
||||
storePosition();
|
||||
} else {
|
||||
playTag(tagId);
|
||||
}
|
||||
}
|
||||
|
||||
void TagPlayerControl::playTag(char* tagId) {
|
||||
Tag tag(tagId);
|
||||
tag.read();
|
||||
currentTag = Tag(tagId);
|
||||
currentTag.read();
|
||||
|
||||
if (tag.isLinked()) {
|
||||
audioPlayer->play(tag.getNextLink());
|
||||
if (currentTag.isLinked()) {
|
||||
audioPlayer->play(currentTag.getNextLink(), currentTag.getCurrentPosition());
|
||||
}
|
||||
}
|
||||
|
||||
void TagPlayerControl::storePosition() {
|
||||
currentTag.setCurrentPosition(0, audioPlayer->getPosition());
|
||||
currentTag.write();
|
||||
}
|
@@ -2,9 +2,11 @@
|
||||
|
||||
#include <memory>
|
||||
#include "AudioPlayer.hpp"
|
||||
#include "Tag.hpp"
|
||||
|
||||
class TagPlayerControl {
|
||||
std::shared_ptr<AudioPlayer> audioPlayer;
|
||||
Tag currentTag;
|
||||
|
||||
public:
|
||||
TagPlayerControl(std::shared_ptr<AudioPlayer> player);
|
||||
@@ -13,4 +15,5 @@ class TagPlayerControl {
|
||||
|
||||
private:
|
||||
void playTag(char* tagId);
|
||||
void storePosition();
|
||||
};
|
Reference in New Issue
Block a user