Playing CDs directly from MPD

Discuss about Hardware diy and tweaks

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.

Playing CDs directly from MPD

Postby Emixam » Sat Jan 10 2015 13:11

Hello
I try since few days to read some audio cd in volumio without riping it.
I've found this tutorial to use fuse/gvfs to do this
http://mpd.wikia.com/wiki/How_to_play_an_audio_cdrom

but i have some issues
Here the step to configure your volumio:

Add gvfs support (fuse and libcdio-paranoia1 are already install)
Code: Select all
apt-update
apt-get install gvfs*


I give right to pi or volumio user

Code: Select all
adduser pi fuse
adduser pi audio
adduser pi cdrom


You must symlink the .gvfs directory into mdp/music:
Code: Select all
cd /var/lib/mpd/music
ln -s /home/<user>/.gvfs/cdda:host=sr0/CDAUDIO


After that we need to mount the cd and update mpd

Code: Select all
dbus-launch gvfs-mount cdda://sr0
mpc update CDAUDIO



(sometimes you have to chown 655 /dev/sr0 before. You can have this error too
Code: Select all
No such interface 'org.gtk.vfs.MountTracker' on object at path /org/gtk/vfs/mounttracker

just retry mounting)

After that we can detect a cdrom and create an automount with cdde and notify
We can play the CD in mpd adding cdda:// in the playlist.

My problem is i can't mount the cd without using sudo or being root. When i do this the cd is mount in /.gvfs/cdda:host=sr0 (you can see wave files) but mpd can't access it.

do you know how to allow mounting gvfs for any user?
I tried to change /etc/fuse.conf but nothing change.

Thank you
User avatar
Emixam
Fresh off the boat
Fresh off the boat
 
Posts: 8
Joined: Sun Jan 04 2015 10:18
Location: Lyon France

Ads helps Volumio remain Free and Open Source. Please consider donating to help us continue to serve you.


Playing CDs directly from MPD

Postby Klaus » Tue Jan 13 2015 20:42

Hi Emixam,

i'm not sure... maybe

Code: Select all
        usermod -aG fuse mpd
        usermod -aG audio mpd
        usermod -aG cdrom mpd


Klaus
User avatar
Klaus
Sunday DIYer
Sunday DIYer
 
Posts: 43
Joined: Tue Jan 21 2014 10:38


Playing CDs directly from MPD

Postby Emixam » Tue Jun 23 2015 14:21

Hi after few month i try to solve this probleme again.
I've been unable to use gvfs-mount but i have a working solution witch need some development.

So, with a fresh installation of volumio 1.55 you need to install:
cdde : to detect cdrom insertion
cdparanoia : to count tracks on cd audio
eject : to ejecct cdrom

Code: Select all
apt-get update
apt-get install cdparanoia eject cdde


You must edit /etc/mdp.conf to alow mpd to use cdparanio plugin to be active

search
Code: Select all
input {
                plugin "curl"
}


and add after:

Code: Select all
input {
                plugin "cdio_paranoia"
}


Now we must add all the tracks to mpd playlist. For now i don't have GUI for that or automatic mounting method i will use in futur cdde.

in /home/volumio create addcdaudio.sh

Code: Select all
#!/bin/bash

#allow access to cdrom
chmod 644 /dev/sr0

#count with cdparanoia the tracks
tracks=$(cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l)

#add each track to mpd playlist
for ((i=1; i<=$tracks; i++)); do
   mpc add cdda:///$i
done


If you launch this script in terminal you should see tracks added into the playlist and you can play them.

To be continued
User avatar
Emixam
Fresh off the boat
Fresh off the boat
 
Posts: 8
Joined: Sun Jan 04 2015 10:18
Location: Lyon France


Playing CDs directly from MPD

Postby Emixam » Tue Jul 21 2015 08:38

Hello
after few month i can now read cd audio from volumio by using mdp. I use a basic cd player connected by usb on a raspberry pi

we need install some package
Code: Select all
apt-get update
apt-get install eject cdparanioa cdde inotify-tools


eject : manage cd ejection (i don't have an eject button on the player i'll use webinterface)
cdparanoia : to count tracks on cd
cdde: to detect cd insertion
inotify-tools: to change file right on cd after insertion

Mpd in Volumio is already compiled with cd support (Thanks) but we must activate it in mpd.conf

Code: Select all
nano /etc/mpd.conf


after this
Code: Select all
input {
      plugin "curl"
}


add

Code: Select all
input {
                plugin "cdio_paranoia"
}


and restart mpd

Code: Select all
/etc/init.d/mpd restart


I assume for this guide that your cdrom is detected on /dev/sr0.

We must create a script witch add cd tracks into mpd playlist

in /home/volumio create the script : "addcdaudio.sh"

Code: Select all
#!/bin/bash

#allow access to cdrom
chmod 644 /dev/sr0

#count with cdparanoia the tracks
tracks=$(cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l)

#add each track to mpd playlist
for ((i=1; i<=$tracks; i++)); do
   mpc add cdda:///$i
done


note: you can add the whole cd by using "mpc add cdda:///" but you'll not be able to change tracks that's why we must count the tracks and add them individually. After cdda command you need to add 3 "/" instead of 2 because mpc remove one without reason

Rights on cdrom must be set each time yon insert a new one so we use cdde
log as volumio and launch cdde
Code: Select all
su volumio
cdde


cdde create a file into /home/volumio/.cdde.xml
We must edit it

Code: Select all
nano /home/volumio/.cdde.xml


change the audio command with this

Code: Select all
<audio command="touch /home/volumio/.cdrom/cdde ; sleep 2s ; rm /home/volumio/.cdrom/cdde"/>


you must check the drive path too:
Code: Select all
<drive path="/dev/sr0">


create folder /home/volumio/.cdrom/
As cdde can't change right on cdrom we create a file into this folder witch be watch by inotify-tools

Create inotify-cdrom file into /home/volumio/bin

Code: Select all
#!/bin/sh
### BEGIN INIT INFO
# Provides:          inotify-cdrom
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

# CONFIGURATION
DOSSIER_SURVEILLE=/home/volumio/.cdrom
# MAIN
inotifywait -m --format '%w%f' -e create $DOSSIER_SURVEILLE | while read LINE
do
chmod 644 /dev/sr0
done


we must activate this at startup

Code: Select all
nano /etc/crontab


add
Code: Select all
@reboot root     /home/volumio/bin/inotify-cdrom
@reboot volumio    cdde -c /home/volumio/.cdde.xml -r


Cron is disable in volumio you must edit the script orion_optimize.sh

Code: Select all
nano /var/www/command/orion_optimize.sh


add a # before killall -9 cron

add www-data to cdrom group

Code: Select all
usermod -aG cdrom www-data


Now you must be able to add cdaudio into mpd by running the addcdaudio.sh script.
The tracks must appear into the playlist and you can play them

To eject the cdrom you must use
Code: Select all
eject /dev/sr0



In order to use it with the regular web interface me must customize some files
first in /var/www create cdaudio.php

Code: Select all
<?php

 
// common include
include('inc/connection.php');
include('inc/player_lib.php');
playerSession('open',$db,'','');
playerSession('unlock',$db,'','');
?>

<?php
if (isset($_POST['syscmd'])){
   switch ($_POST['syscmd']) {

   case 'eject':
   
         
         
         $cmd = 'eject /dev/sr0';
         sysCmd($cmd);
         
         session_start();
         $_SESSION['w_active'] = 1;
         // set UI notify
         $_SESSION['notify']['title'] = 'EJECT';
         $_SESSION['notify']['msg'] = 'Ejecting cd...';
         // unlock session file
         playerSession('unlock');
         
      break;
      
   case 'addcd':
         
         $cmdadd = '/var/www/command/addcdaudio.sh';
         sysCmd($cmdadd);

         session_start();;
         // set UI notify
         $_SESSION['notify']['msg'] = 'Adding CD Audio...';
         // unlock session file
         playerSession('unlock');
         
         
      break;
   
   case 'addplaycd':
         
         $cmdadd = '/var/www/command/addcdaudio.sh';
         sysCmd($cmdadd);
         
         session_start();
         sendMpdCommand($mpd,'play');
         // set UI notify
         $_SESSION['notify']['msg'] = 'Adding CD Audio...';
         // unlock session file
         playerSession('unlock');
         
         
      break;
   
   case 'addreplacecd':
         sendMpdCommand($mpd,'clear');
         $cmdadd = '/var/www/command/addcdaudio.sh';
         sysCmd($cmdadd);
         
         session_start();
         sendMpdCommand($mpd,'play');
         // set UI notify
         $_SESSION['notify']['msg'] = 'Adding CD Audio...';
         // unlock session file
         playerSession('unlock');
         
         
      break;
   }

}
header('Location: /index.php');
?>




I've be unable to add entry into the browser tab so i change the menu.

edit /var/www/_header.php

after
Code: Select all
<li class="<?php ami('sources'); ?>"><a href="sources.php"><i class="fa fa-folder-open sx"></i> Library</a></li>


add
Code: Select all
<li><a href="#cdaudio-modal" data-toggle="modal"><i class="fa fa-dot-circle-o sx"></i> CD Audio</a></li>



edit /var/www/_footer.php


Before
Code: Select all
<!-- loader -->

   



add
Code: Select all
<form class="form-horizontal" action="cdaudio.php" method="post">
   <div id="cdaudio-modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="cdaudio-modal-label" aria-hidden="true">
      <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
         <h3 id="poweroff-modal-label">Manage CD Audio</h3>
      </div>
      <div class="modal-body">
         <button id="syscmd-addcd" name="syscmd" value="addcd" class="btn btn-primary btn-large btn-block"><i class="fa fa-plus sx"></i> Add</button>
         <button id="syscmd-poweroff" name="syscmd" value="addplaycd" class="btn btn-primary btn-large btn-block"><i class="fa fa-play sx"></i> Add and Play</button>
         <button id="syscmd-poweroff" name="syscmd" value="addreplacecd" class="btn btn-primary btn-large btn-block"><i class="fa fa-share sx"></i> Add, replace and play</button>
         <button id="syscmd-eject" name="syscmd" value="eject" class="btn btn-primary btn-large btn-block"><i class="fa fa-eject sx"></i> Eject</button>
      </div>
      <div class="modal-footer">
         <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
      </div>
   </div>
</form>



I hope i didn't forgot something maybe some user and files rights must be set but i've test so many configurations....
User avatar
Emixam
Fresh off the boat
Fresh off the boat
 
Posts: 8
Joined: Sun Jan 04 2015 10:18
Location: Lyon France


Playing CDs directly from MPD

Postby csw » Sun Sep 06 2015 08:24

Hi Emixam,

thanks for all the work.
I'm completely new to the Pi and started by setting up Volumio at home. The USB-CD functionality is exactly what I was looking for.

So at the moment, I am still a bit overwhelmed by what needs to be done although I find your guide very detailed and can imagine trying it out.
That will take me a while though, so I wanted to leave a post here to say it would be great to have this implemented in Volumio for out of the box use.

Is there a way to enable some kind of autoplay after inserting the CD?

Thanks again and I hope this great work will find a lot of fans.
Best,
Chris
Random avatar
csw
Fresh off the boat
Fresh off the boat
 
Posts: 1
Joined: Sun Sep 06 2015 08:09


Playing CDs directly from MPD

Postby Emixam » Fri Sep 11 2015 07:57

Hi Chris
I hope too this to be implemented in volumio in futurs release but not like this i think. I wait for volumio 2 and if i can propose something more integrated with volumio UI. (if i'm able to code)
The good thing is that mpd is already compile by volumio team with the appropriated plugin.

You can define an autoplay (not with the web interface) by adding "mpc play" like this:

/home/volumio create the script : "addcdaudio.sh"


Code: Select all
#!/bin/bash

    #allow access to cdrom
    chmod 644 /dev/sr0

    #count with cdparanoia the tracks
    tracks=$(cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l)

    #add each track to mpd playlist
    for ((i=1; i<=$tracks; i++)); do
       mpc add cdda:///$i
       mpc play
    done
User avatar
Emixam
Fresh off the boat
Fresh off the boat
 
Posts: 8
Joined: Sun Jan 04 2015 10:18
Location: Lyon France


Playing CDs directly from MPD

Postby moosensquirrel » Wed Feb 24 2016 19:08

Hi, Emixam. Thanks for your instructions. I was able to add the code and make the edits you recommended, and now I can play CDs from a USB CD/DVD player. This is a major accomplishment.

I have one problem, though. When I click any of the buttons to add tracks to the playlist, the tracks are added, but they will not play. If I add the tracks via SSH and the command line running addcdaudio.sh, the tracks show up in the playlist and can be played normally. However, if I use the web interface, the tracks are added to the playlist, but I cannot select a track and clicking the play button does nothing.

Any suggestions you can offer would be appreciated!

Thanks!!

David
Random avatar
moosensquirrel
Fresh off the boat
Fresh off the boat
 
Posts: 1
Joined: Wed Feb 24 2016 18:59


Playing CDs directly from MPD

Postby Emixam » Tue Mar 29 2016 20:03

Hi david sorry for the delay

Maybe you can try add mpd or volumio to the cdrom group like we did for www-data:

Code: Select all
usermod -aG cdrom www-data

be sure to have into addcdaudio.sh
Code: Select all
#allow access to cdrom
chmod 644 /dev/sr0


When you try from command line witch account do you use?
User avatar
Emixam
Fresh off the boat
Fresh off the boat
 
Posts: 8
Joined: Sun Jan 04 2015 10:18
Location: Lyon France


Playing CDs directly from MPD

Postby chrisb911 » Wed Apr 06 2016 18:06

hi Emixam,

Thanks also for this - great work!

However, I have the same issue as David - I can make it work from the command line (logged in as volume account and running script using sudo) but it doesn't work from the 'CD Audio' panel in the volume interface.

I did get it working on one occasion but not sure what I did - I expect it was setting permissions on /dev/sr0

I tried adding the user permissions as described but makes no difference.

Any other ideas?

Chris
Random avatar
chrisb911
Fresh off the boat
Fresh off the boat
 
Posts: 1
Joined: Sun Jan 31 2016 19:36


Playing CDs directly from MPD

Postby Fightclub » Thu May 05 2016 12:35

Hi everyone,

I tried reproducing the results from the guide on Volumio 2RC1, but have some problems with mpd. I can add tracks, but if I try to play them, it takes a ridiculous amount of time (~10s) to buffer 10% of 8kb, then it starts playing for ~3s-4s and then starts stuttering/jittering like crazy.
To me this looks like serious buffer underrun, but I can't find the reason why. The drive seems to be okay: drive speed of 24x should be fast enough, also 8x to prevent early spindown and if I connect it to my mac it plays flawlessly.
My next suspicion was cdparanoia, but if I comment out the input plugin part situation doesn't change. Also if I run cdparanoia standalone it rips the track of 2:19min in 1:41min.
So right now I have no clue what's going on and why it's got these problems with mpd. Any ideas from the community?
User avatar
Fightclub
Serious Listener
Serious Listener
 
Posts: 80
Joined: Tue Feb 09 2016 18:28
Location: Germany

Next

Return to Diy and Tweaks

Who is online

Users browsing this forum: No registered users and 0 guests