mirror of
https://github.com/sweidac/kidsbox.git
synced 2026-10-28 06:52:57 +01:00
- rc522: add NDEF URL reading via WUPA+cascade anticoll+SELECT+TLV parse
- AudioPlayer: route http:// URIs to esp_player_http_music_play()
- CacheManager: download URLs async to /sdcard/cache/{hash}.{ext}
- TagPlayerControl: NDEF URL → cache-or-stream; fallback to UID local mapping
- RFIDInterface: wire ndef_callback, expose combined uid+url callback
- WebInterface: add /api/info, /api/storage, /api/playback, /api/bluetooth
- BluetoothInterface: stub for A2DP speaker mode
- Networking: WiFi connect with 30s timeout instead of blocking forever
- main.cpp: re-enable WiFi + web server, fix init order, add CacheManager
- www/: full SPA — playback controls, device info, storage, BT pairing
- .gitmodules: switch rc522 submodule URL to HTTPS
https://claude.ai/code/session_01MhAnh68DPNnTjcKqjNYDmk
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "AudioPlayer.hpp"
|
|
|
|
#include <esp_player_wrapper.h>
|
|
#include "audio_setup.h"
|
|
#include <esp_log.h>
|
|
|
|
static const char* TAG = "AudioPlayer";
|
|
|
|
AudioPlayer::AudioPlayer() {
|
|
playerHandle = setup_player(NULL, NULL);
|
|
esp_player_init((esp_audio_handle_t)playerHandle);
|
|
esp_audio_vol_set((esp_audio_handle_t)playerHandle, 50);
|
|
}
|
|
|
|
bool AudioPlayer::isHttpUri(const std::string& uri) const {
|
|
return uri.rfind("http://", 0) == 0 || uri.rfind("https://", 0) == 0;
|
|
}
|
|
|
|
bool AudioPlayer::isLastUri(const std::string& uri) const {
|
|
return lastUri == uri;
|
|
}
|
|
|
|
void AudioPlayer::play(const std::string& uri) {
|
|
if(isLastUri(uri)) {
|
|
esp_player_music_resume();
|
|
return;
|
|
}
|
|
|
|
esp_player_music_stop();
|
|
lastUri = uri;
|
|
|
|
if(isHttpUri(uri)) {
|
|
ESP_LOGI(TAG, "Streaming: %s", uri.c_str());
|
|
esp_player_http_music_play(uri.c_str(), 0);
|
|
} else {
|
|
ESP_LOGI(TAG, "Playing local: %s", uri.c_str());
|
|
esp_player_sdcard_music_play(uri.c_str(), 0);
|
|
}
|
|
}
|
|
|
|
void AudioPlayer::pause() {
|
|
esp_player_music_pause();
|
|
}
|
|
|
|
void AudioPlayer::stop() {
|
|
esp_player_music_stop();
|
|
lastUri.clear();
|
|
}
|
|
|
|
int AudioPlayer::getVolume() {
|
|
int vol = 0;
|
|
esp_player_vol_get(&vol);
|
|
return vol;
|
|
}
|
|
|
|
void AudioPlayer::setVolume(int vol) {
|
|
if(vol < 0) vol = 0;
|
|
if(vol > 100) vol = 100;
|
|
esp_audio_vol_set((esp_audio_handle_t)playerHandle, vol);
|
|
}
|
|
|
|
bool AudioPlayer::isPlaying() const {
|
|
esp_audio_state_t state;
|
|
if(esp_player_state_get(&state) != ESP_OK) return false;
|
|
return state.status == AUDIO_STATUS_RUNNING;
|
|
}
|