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);
|
esp_audio_vol_set(playerHandle, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioPlayer::play(std::string uri) {
|
void AudioPlayer::play(std::string uri, int position = 0) {
|
||||||
if (isLastUri(uri)) {
|
if (isLastUri(uri)) {
|
||||||
esp_player_music_resume();
|
esp_player_music_resume();
|
||||||
} else {
|
} else {
|
||||||
esp_player_music_stop();
|
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);
|
lastUri = std::string(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,4 +28,12 @@ void AudioPlayer::pause() {
|
|||||||
|
|
||||||
bool AudioPlayer::isLastUri(std::string uri) {
|
bool AudioPlayer::isLastUri(std::string uri) {
|
||||||
return lastUri == uri;
|
return lastUri == uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
int AudioPlayer::getPosition() {
|
||||||
|
int position;
|
||||||
|
|
||||||
|
esp_player_pos_get(&position);
|
||||||
|
|
||||||
|
return position;
|
||||||
}
|
}
|
@@ -8,8 +8,10 @@ class AudioPlayer {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
AudioPlayer();
|
AudioPlayer();
|
||||||
void play(std::string uri);
|
|
||||||
|
void play(std::string uri, int position);
|
||||||
void pause();
|
void pause();
|
||||||
|
int getPosition();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isLastUri(std::string uri);
|
bool isLastUri(std::string uri);
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Tag::Tag() {}
|
||||||
|
|
||||||
Tag::Tag(char* tagId): Tag(std::string(tagId)) {
|
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>();
|
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() {
|
std::string Tag::getNextLink() {
|
||||||
return this->playlist.at(this->currentFileIndex);
|
return this->playlist.at(this->currentFileIndex);
|
||||||
}
|
}
|
||||||
@@ -90,6 +101,8 @@ void Tag::read() {
|
|||||||
void Tag::write() {
|
void Tag::write() {
|
||||||
std::string contents = createFileContents();
|
std::string contents = createFileContents();
|
||||||
|
|
||||||
|
std::cout << contents << std::endl;
|
||||||
|
|
||||||
std::string filePath = getFilePath();
|
std::string filePath = getFilePath();
|
||||||
|
|
||||||
std::ofstream file(filePath);
|
std::ofstream file(filePath);
|
||||||
|
@@ -11,12 +11,15 @@ class Tag {
|
|||||||
uint32_t currentFilePosition{0};
|
uint32_t currentFilePosition{0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Tag();
|
||||||
Tag(std::string tagId);
|
Tag(std::string tagId);
|
||||||
Tag(char* tagId);
|
Tag(char* tagId);
|
||||||
void read();
|
void read();
|
||||||
void write();
|
void write();
|
||||||
bool isLinked();
|
bool isLinked();
|
||||||
std::string getNextLink();
|
std::string getNextLink();
|
||||||
|
void setCurrentPosition(uint32_t fileIndex, uint32_t position);
|
||||||
|
int getCurrentPosition();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string createFileContents();
|
std::string createFileContents();
|
||||||
|
@@ -20,16 +20,22 @@ void TagPlayerControl::onTagChanged(char* tagId) {
|
|||||||
if (tagId == NULL) {
|
if (tagId == NULL) {
|
||||||
// tag has been removed. stop playback
|
// tag has been removed. stop playback
|
||||||
audioPlayer->pause();
|
audioPlayer->pause();
|
||||||
|
storePosition();
|
||||||
} else {
|
} else {
|
||||||
playTag(tagId);
|
playTag(tagId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TagPlayerControl::playTag(char* tagId) {
|
void TagPlayerControl::playTag(char* tagId) {
|
||||||
Tag tag(tagId);
|
currentTag = Tag(tagId);
|
||||||
tag.read();
|
currentTag.read();
|
||||||
|
|
||||||
if (tag.isLinked()) {
|
if (currentTag.isLinked()) {
|
||||||
audioPlayer->play(tag.getNextLink());
|
audioPlayer->play(currentTag.getNextLink(), currentTag.getCurrentPosition());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagPlayerControl::storePosition() {
|
||||||
|
currentTag.setCurrentPosition(0, audioPlayer->getPosition());
|
||||||
|
currentTag.write();
|
||||||
}
|
}
|
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "AudioPlayer.hpp"
|
#include "AudioPlayer.hpp"
|
||||||
|
#include "Tag.hpp"
|
||||||
|
|
||||||
class TagPlayerControl {
|
class TagPlayerControl {
|
||||||
std::shared_ptr<AudioPlayer> audioPlayer;
|
std::shared_ptr<AudioPlayer> audioPlayer;
|
||||||
|
Tag currentTag;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TagPlayerControl(std::shared_ptr<AudioPlayer> player);
|
TagPlayerControl(std::shared_ptr<AudioPlayer> player);
|
||||||
@@ -13,4 +15,5 @@ class TagPlayerControl {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void playTag(char* tagId);
|
void playTag(char* tagId);
|
||||||
|
void storePosition();
|
||||||
};
|
};
|
Reference in New Issue
Block a user