Skip to content

Commit 8111587

Browse files
committed
DLNA playlist first impl. #451
1 parent 218d600 commit 8111587

File tree

2 files changed

+71
-17
lines changed

2 files changed

+71
-17
lines changed

src/common.h

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ bool connectToWiFi();
211211
void openAccessPoint();
212212
const char* scaleImage(const char* path);
213213
void setVolume(uint8_t vol);
214-
inline uint8_t getvolume();
215214
uint8_t downvolume();
216215
uint8_t upvolume();
217216
void setStation(uint16_t sta);
@@ -226,6 +225,7 @@ void SD_playFile(const char* path, uint32_t resumeFilePos = 0, bool sh
226225
bool SD_rename(const char* src, const char* dest);
227226
bool SD_newFolder(const char* folderPathName);
228227
bool SD_delete(const char* itemPath);
228+
bool preparePlaylistFromDLNAFolder();
229229
bool preparePlaylistFromFile(const char* path);
230230
bool preparePlaylistFromFolder(const char* path);
231231
void sortPlayListAlphabetical();
@@ -1766,15 +1766,15 @@ class dlnaList{
17661766
return true;
17671767
}
17681768

1769-
void longPressed(uint16_t x, uint16_t y){ // is unused
1769+
void longPressed(uint16_t x, uint16_t y){
17701770
bool maybe_a_server = false;
17711771
bool maybe_a_file = false;
17721772
bool maybe_a_folder = false;
1773-
m_clicked = false; // ignore tp released event, wait of next clicked
1773+
m_clicked = false; // ignore tp released event, wait of next clicked
17741774
m_itemListPos = (y / (m_h / 10));
1775-
if(m_itemListPos == 0) goto exit; // is header
1776-
if(m_itemListPos == 1) {log_i("long pressed at return item %s", m_dlnaHistory[*m_dlnaLevel].name); goto exit;}
1777-
if(m_itemListPos >= 11) goto exit; // is footer
1775+
if(m_itemListPos == 0) goto exit; // is header
1776+
if(m_itemListPos == 1) { /* log_i("long pressed at return item %s", m_dlnaHistory[*m_dlnaLevel].name); */ goto exit;}
1777+
if(m_itemListPos >= 11) goto exit; // is footer
17781778

17791779
m_itemListPos -= 2;
17801780

@@ -1787,19 +1787,24 @@ class dlnaList{
17871787
}
17881788

17891789
if(maybe_a_server){
1790-
log_i("long pressed at server %s", m_dlnaServer.friendlyName[m_itemListPos]);
1791-
goto exit;
1790+
/* log_i("long pressed at server %s", m_dlnaServer.friendlyName[m_itemListPos]); */ goto exit;
17921791
}
17931792

17941793
if(maybe_a_file){
17951794
if(startsWith(m_srvContent.itemURL[m_itemListPos], "http")){
1796-
log_i("long pressed at file %s", m_srvContent.itemURL[m_itemListPos]);
1797-
goto exit;
1795+
/* log_i("long pressed at file %s", m_srvContent.itemURL[m_itemListPos]); */ goto exit;
17981796
}
17991797
}
18001798

18011799
if(maybe_a_folder){
1802-
log_i("long pressed at folder x %s",m_srvContent.title[m_itemListPos]);
1800+
// log_i("long pressed at folder x %s",m_srvContent.title[m_itemListPos]);
1801+
tft.setTextColor(TFT_MAGENTA);
1802+
tft.setFont(m_fontSize);
1803+
tft.writeText(m_srvContent.title[m_itemListPos], 20, m_y + (m_itemListPos + 1) * m_lineHight, m_w - 20, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
1804+
1805+
m_ra.arg1 = m_srvContent.objectId[m_itemListPos];
1806+
m_ra.val2 = m_currDLNAsrvNr;
1807+
m_ra.val1 = 2;
18031808
goto exit;
18041809
}
18051810

@@ -1808,6 +1813,14 @@ class dlnaList{
18081813
return;
18091814
}
18101815

1816+
void longReleased(){
1817+
if(!m_enabled) return;
1818+
if(!m_clicked) return;
1819+
if(graphicObjects_OnRelease) graphicObjects_OnRelease((const char*)m_name, m_ra);
1820+
m_ra.val1 = 0;
1821+
m_clicked = false;
1822+
}
1823+
18111824
private:
18121825
void dlnaItemsList(){
18131826
if(!m_buff) m_buff = x_ps_malloc(512);

src/main.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MiniWebRadio -- Webradio receiver for ESP32
55
66
first release on 03/2017 */String Version ="\
7-
Version 3.1d Jun 10/2024 ";
7+
Version 3.1e Jun 11/2024 ";
88

99
/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
1010
3.5" color display (480x320px) wiht controller ILI9486 or ILI9488 (SPI)
@@ -165,6 +165,8 @@ bool _f_shuffle = false;
165165
bool _f_dlnaBrowseServer = false;
166166
bool _f_dlnaWaitForResponse = false;
167167
bool _f_dlnaSeekServer = false;
168+
bool _f_dlnaMakePlaylistOTF = false; // notify callback that this browsing was to build a On-The_fly playlist
169+
bool _f_dlna_browseReady = false;
168170
bool _f_BtEmitterFound = false;
169171
bool _f_BTEmitterConnected = false;
170172
bool _f_brightnessIsChangeable = false;
@@ -1116,6 +1118,29 @@ bool preparePlaylistFromFolder(const char* path) { // all files whithin a folder
11161118
return true;
11171119
}
11181120
//____________________________________________________________________________________________________________________________________________________
1121+
bool preparePlaylistFromDLNAFolder(){
1122+
vector_clear_and_shrink(_PLS_content); // clear _PLS_content first
1123+
DLNA_Client::srvContent_t foldercontent = dlna.getBrowseResult();
1124+
for ( int i=0; i<foldercontent.size; i++) {
1125+
// log_i( "%d : (%d) %s %s -- %s",i, foldercontent.isAudio[i], foldercontent.itemURL[i], foldercontent.title[i], foldercontent.duration[i]);
1126+
if(!foldercontent.isAudio[i]) continue;
1127+
uint16_t len = strlen((const char*)foldercontent.itemURL[i]) + strlen((const char*)foldercontent.title[i]) + strlen((const char*)foldercontent.duration[i]) + 3;
1128+
// log_i("malloc with size %d %d %d %d",len, strlen((const char*)foldercontent.itemURL[i]), strlen((const char*)foldercontent.title[i]), strlen((const char*)foldercontent.duration[i]));
1129+
char* itstr = x_ps_malloc( len );
1130+
strcpy( itstr, (const char*)foldercontent.itemURL[i]);
1131+
strcat( itstr, "\n");
1132+
strcat( itstr, (const char*)foldercontent.duration[i]);
1133+
strcat( itstr, ",");
1134+
strcat( itstr, (const char*)foldercontent.title[i]);
1135+
log_i("pushing to playlist : %s",itstr);
1136+
_PLS_content.push_back(itstr);
1137+
//_PLS_content.push_back(x_ps_strdup((const char*)foldercontent.itemURL[i]));
1138+
}
1139+
if(!_PLS_content.size()) return false;
1140+
log_i("pls length %i", _PLS_content.size());
1141+
return true;
1142+
}
1143+
//____________________________________________________________________________________________________________________________________________________
11191144

11201145
void sortPlayListAlphabetical() {
11211146
for(int i = 0; i < _PLS_content.size(); i++) { // easy bubble sort
@@ -2621,6 +2646,16 @@ void loop() {
26212646
_f_dlnaSeekServer = false;
26222647
dlna.seekServer();
26232648
}
2649+
//------------------------------------------CREATE DLNA PLAYLIST------------------------------------------------------------------------------
2650+
if(_f_dlnaMakePlaylistOTF && _f_dlna_browseReady){
2651+
_f_dlnaMakePlaylistOTF = false;
2652+
_f_dlna_browseReady = false;
2653+
if(preparePlaylistFromDLNAFolder()) processPlaylist(true);
2654+
}
2655+
//------------------------------------------DLNA ITEMS RECEIVED-------------------------------------------------------------------------------
2656+
if(_f_dlna_browseReady){ // unused
2657+
_f_dlna_browseReady = false;
2658+
}
26242659
//------------------------------------------GET AUDIO FILE ITEMS------------------------------------------------------------------------------
26252660
if(_f_isFSConnected) {
26262661
// uint32_t t = 0;
@@ -2704,7 +2739,6 @@ void audio_info(const char* info) {
27042739
log_w("disconnected, wait 35s");
27052740
vTaskDelay(35000 / portTICK_PERIOD_MS);
27062741
log_w("try reconnection");
2707-
_reconnectCnt = 0;
27082742
_f_reconnect = true;
27092743
}return;}
27102744
if(startsWith(info, "FLAC")) {SerialPrintflnCut("AUDIO_info: ", ANSI_ESC_GREEN, info); return;}
@@ -3087,6 +3121,7 @@ void tp_released(uint16_t x, uint16_t y){
30873121

30883122
void tp_long_released(){
30893123
// log_w("long released)");
3124+
if(_state == DLNAITEMSLIST) {lst_DLNA.longReleased();}
30903125
}
30913126
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
30923127
void tp_positionXY(uint16_t x, uint16_t y){
@@ -3411,8 +3446,8 @@ void dlna_browseResult(const char* objectId, const char* parentId, uint16_t chil
34113446
void dlna_browseReady(uint16_t numberReturned, uint16_t totalMatches) {
34123447
SerialPrintfln("DLNA_server: returned %i from %i", numberReturned + _totalNumberReturned, totalMatches);
34133448
_dlnaMaxItems = totalMatches;
3414-
if(numberReturned == 50) { // next round
3415-
_totalNumberReturned += numberReturned;
3449+
_totalNumberReturned += numberReturned;
3450+
if(numberReturned == 50 && !_f_dlnaMakePlaylistOTF) { // next round
34163451
if(_totalNumberReturned < totalMatches && _totalNumberReturned < 500) { _f_dlnaBrowseServer = true; }
34173452
}
34183453
if(_f_dlnaWaitForResponse) {
@@ -3421,6 +3456,10 @@ void dlna_browseReady(uint16_t numberReturned, uint16_t totalMatches) {
34213456
setTimeCounter(4);
34223457
}
34233458
else { webSrv.send("dlnaContent=", dlna.stringifyContent()); }
3459+
if(_totalNumberReturned == totalMatches || _totalNumberReturned == 500 || _f_dlnaMakePlaylistOTF){
3460+
_totalNumberReturned = 0;
3461+
_f_dlna_browseReady = true; // last item received
3462+
}
34243463
}
34253464
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
34263465
void kcx_bt_info(const char* info, const char* val) {
@@ -3538,7 +3577,7 @@ void graphicObjects_OnClick(const char* name, uint8_t val) { // val = 0 --> is d
35383577
if( val && strcmp(name, "btn_DL_cancel") == 0) {clearStationName(); btn_DL_pause.setInactive(); return;}
35393578
}
35403579
if(_state == DLNAITEMSLIST) {
3541-
if( val && strcmp(name, "lst_DLNA") == 0) {setTimeCounter(6); _f_dlnaWaitForResponse = true; return;}
3580+
if( val && strcmp(name, "lst_DLNA") == 0) {setTimeCounter(15); _f_dlnaWaitForResponse = true; return;}
35423581
}
35433582
if(_state == CLOCK) {
35443583
if( val && strcmp(name, "btn_CL_Mute") == 0) {setTimeCounter(2); if(!_f_mute){ _f_muteIsPressed = true;} return;}
@@ -3640,7 +3679,9 @@ void graphicObjects_OnRelease(const char* name, releasedArg ra) {
36403679
if(strcmp(name, "btn_DL_cancel") == 0) {stopSong(); txt_DL_fName.setText(""); return;}
36413680
}
36423681
if(_state == DLNAITEMSLIST) {
3643-
if(strcmp(name, "lst_DLNA") == 0) {if(ra.val1){txt_DL_fName.setTextColor(TFT_CYAN); txt_DL_fName.setText(ra.arg2, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER); changeState(DLNA); connecttohost(ra.arg1);} return;}
3682+
if(strcmp(name, "lst_DLNA") == 0) {if(ra.val1 == 1){txt_DL_fName.setTextColor(TFT_CYAN); txt_DL_fName.setText(ra.arg2, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER); changeState(DLNA); connecttohost(ra.arg1);} // play a file
3683+
if(ra.val1 == 2){dlna.browseServer(ra.val2, ra.arg1, 0, 50); _f_dlnaMakePlaylistOTF = true; } // browse dlna object, waiting for content and create a playlist
3684+
return;}
36443685
}
36453686
if(_state == CLOCK) {
36463687
if(strcmp(name, "btn_CL_Mute") == 0) {muteChanged(btn_CL_Mute.getValue()); return;}

0 commit comments

Comments
 (0)