The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.34 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Problem: Looking for help with using RFID tag to que music from local album location
#1
Hi, nice to meet you all.

I'm currently deep into a project where I'm having trouble configuring moode to que a playlist from reading an RFID tag.

I'm using a Rpi 4, an mfrc522 rfid moldule.

Here's how i've set my features.

Currently, local music is stored on the sd card, in /var/lib/mpd/music/artists/{artist}/{album}/{mp3 files of the album here}

my /etc/mpd.conf file, music directory = /var/lib/mpd/music

Code:
#########################################
# This file is automatically generated
# by the MPD configuration page.
#########################################

music_directory "/var/lib/mpd/music"
playlist_directory "/var/lib/mpd/music/playlists"
db_file "/var/lib/mpd/database"
log_file "/var/log/mpd/log"
pid_file "/var/run/mpd/pid"
state_file "/var/lib/mpd/state"
sticker_file "/var/lib/mpd/sticker.sql"
user "mpd"
group "audio"
bind_to_address "any"
port "6600"
log_level "default"
restore_paused "yes"
auto_update "no"
follow_outside_symlinks "yes"
follow_inside_symlinks "yes"
zeroconf_enabled "no"
zeroconf_name "Pi MPD"
filesystem_charset "UTF-8"
metadata_to_use "+comment"
replaygain "off"
replaygain_preamp "0"
volume_normalization "no"
audio_buffer_size "4096"
max_output_buffer_size "131072"
max_playlist_length "16384"
max_connections "128"

decoder {
plugin "ffmpeg"
enabled "yes"
}

input {
plugin "curl"
proxy ""
proxy_user ""
proxy_password ""
}

resampler {


music is uploaded in a structure that verifies metadata using mutagen in a class specifically for uploading via usb. titles for albums in this structure are organized by '{artist} | {album}' and then written this way to the rfid tag.

my playback class file takes this data and searches the directory /var/lib/mpd/music/artists to first find {artist} then searches for {album}, then attempts to use the {add} function to add the album mp3 files to the moodeaudio player

Snippet of relevant code. 

Code:
   def __init__(self, music_dir='/var/lib/mpd/music/artists', mpd_host='localhost', mpd_port=6600):

#  other int something something is here.. #
   
   def find_music_files(self, artist, album):
       artist_path = os.path.join(self.music_dir, artist)
       album_path = os.path.join(artist_path, album)
       if os.path.exists(album_path) and os.path.isdir(album_path):
           print("find music found the music!")
           return [os.path.join(album_path, file) for file in os.listdir(album_path) if file.endswith('.mp3')]
           print(f"find music file: {artist},{album}")
       return []

   def play_music(self, artist, album):
       try:
           base_path = '/var/lib/mpd/music/artists'
           album_path = os.path.join(base_path, artist, album)

           if os.path.exists(album_path):
               print("play mus knows file exists!")
               for root, dirs, files in os.walk(album_path):
                   for file in files:
                       file_path = os.path.join(root, file)
                       print("i'm attempting to add the music!")
                       self.mpd_client.add(file_path)
                       print("attempt to add music to queue")
               print("Im attempting to play the music!")
               self.mpd_client.play()
           else:
               print(f"Album not found: {artist} - {album}")

       except Exception as e:
           print(f"An error occurred: {e}")


   def stop_music(self):
       self.mpd_client.stop()
       self.mpd_client.clear()

   def run(self):
       while True:
           artist, album = self.read_rfid_tag()
           if artist and album:
               if self.current_tag != (artist, album):
                   self.current_tag = (artist, album)
                   files = self.find_music_files(artist, album)
                   if files:
                       self.play_music(artist, album)
                   else:
                       print("No music files found for the given artist and album.")

I'm having trouble with permissions, all permissions are valid for read/write access for the user and group mpd:audio, the class file is able to read the tag, locate the music path, verify the music exists, and attempts to add the music. Then I get an output error "An error occurred: [4@0] {add} Access denied"

Code:
Initial mode set to Moodeaudio
Rfid tag read data!
find music found the music!
play mus knows file exists!
i'm attempting to add the music!
An error occurred: [4@0] {add} Access denied

I would be interested to know if anyone here has a similar setup, and is willing to share how they achieved it, if anyone knows how I can grand access to the {add} command, or if I'm missing something on how I built the feature.

Thanks!
Reply


Messages In This Thread
Looking for help with using RFID tag to que music from local album location - by Rtune - 08-01-2024, 06:42 PM

Forum Jump: