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
#2
I'm having a hard time understanding this usage scenario that uses RFID tags but in any case refer to the MPD documentation for the permission requirements.

https://mpd.readthedocs.io/en/latest/use...d-database
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply
#3
(08-01-2024, 07:05 PM)Tim Curtis Wrote: I'm having a hard time understanding this usage scenario that uses RFID tags but in any case refer to the MPD documentation for the permission requirements.

https://mpd.readthedocs.io/en/latest/use...d-database

My main script has multiple modes. When in the first mode, the rfid module loops to read/search for an rfid tag to be presented. When the rfid module detects a tag with the data '{artist} | {album}', the rfid_playback_handler class is called, which is where those functions I posted are located. To locate music, and then add that music to que in the library, and run the play command to begin playing the album.

Let me know if that's any more clear, thank you.
Reply
#4
@Rtune

The Python snippet doesn't include the actual add code. I'm going to assume it call mpc add with the file_path argument. Looks like file_path is absolute, e.g., relative to /

That won't work because mpd and mpc use paths relative to the music_directory path given in mpd.conf.

Here's a test on a moOde 9.0.5 player where I try to add the Stereo test file to the queue, first with an absolute file_path, second with the relative file_path

Code:
rho@purple:~ $ mpc add /mnt/SDCARD/Stereo\ Test/LRMonoPhase4.flac
error adding /mnt/SDCARD/Stereo Test/LRMonoPhase4.flac: Access denied
rho@purple:~ $ mpc add SDCARD/Stereo\ Test/LRMonoPhase4.flac
rho@purple:~ $

Regards,
Kent
Reply
#5
(08-01-2024, 07:11 PM)Rtune Wrote:
(08-01-2024, 07:05 PM)Tim Curtis Wrote: I'm having a hard time understanding this usage scenario that uses RFID tags but in any case refer to the MPD documentation for the permission requirements.

https://mpd.readthedocs.io/en/latest/use...d-database

My main script has multiple modes. When in the first mode, the rfid module loops to read/search for an rfid tag to be presented. When the rfid module detects a tag with the data '{artist} | {album}', the rfid_playback_handler class is called, which is where those functions I posted are located. To locate music, and then add that music to que in the library, and run the play command to begin playing the album.

Let me know if that's any more clear, thank you.

I am making a guess that you have RFID tags on your physical albums and this routine scans the tag when you hold the physical media close to the player and starts playing the digital version.  If I'm right, that's very cool, I hope you get it working.
----------------
Robert
Reply


Forum Jump: