menu_playlist kirkstone
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 12 Nov 2024 03:40:08 +0000 (22:40 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Tue, 12 Nov 2024 03:43:53 +0000 (22:43 -0500)
recipes-multimedia/hvmpd-manager/files/hvmpd.sh

index dde10c8..08eba90 100644 (file)
@@ -113,8 +113,34 @@ key_pressed() {
     return ${rc}
 }
 
+list_id=0
+list_count=0
+menu=0
+
+PLAYLIST_DIR="/var/lib/mpd/playlists"
+
+playlists_get() {
+    files=$(ls ${PLAYLIST_DIR}/*.m3u)
+
+    # Clear list
+    pl=()
+
+    for f in ${files}; do
+        f=$(basename ${f} .m3u)
+        #log_info "f=$f"
+        pl+=("${f}")
+    done
+
+    list_count="${#pl[@]}"
+
+    ##log_info "count=${list_count}"
+    ##log_info "pl=${pl[@]}"
+}
+
 keys_manager() {
     while true; do
+        playlists_get
+
         if key_pressed KEY_PLAYPAUSE ; then
             log_info "mpc toggle"
 
@@ -125,7 +151,46 @@ keys_manager() {
             fi
         fi
 
+        if key_pressed KEY_UP ; then
+            menu=1
+
+            if [ ${list_id} -gt 0 ]; then
+                list_id=$((${list_id} - 1))
+            fi
+        fi
+
+        if key_pressed KEY_DOWN ; then
+            menu=1
+
+            list_id=$((${list_id} + 1))
+
+            if [ ${list_id} -ge ${list_count} ]; then
+                list_id=$((${list_id} - 1))
+            fi
+        fi
+
+        if key_pressed KEY_LEFT ; then
+            menu=1
+        fi
+
+        if key_pressed KEY_RIGHT ; then
+            menu=1
+        fi
+
+        if key_pressed KEY_ENTER ; then
+            menu=1
+        fi
+
+        if [ ${menu} -eq 1 ]; then
+            if is_mpc_playing ; then
+                mpc stop 1> /dev/null
+
+            log_info "menu = ${pl[${list_id}]}"
+            menu=0
+        fi
+
         if is_mpc_playing ; then
+            menu=0
            led_on
             log_dbg "[playing]"
         else
@@ -139,6 +204,9 @@ keys_manager() {
 
 lcd_init
 
+#playlists_get
+#exit 1
+
 # Start function in the background
 keys_manager &