A Raspberry Pi Subsonic Jukebox using Java 8

In the comments of my Install Subsonic media streaming server on a Raspberry Pi post, Ross very kindly posted some instructions on how to get the Jukebox mode of Subsonic working on the Raspberry Pi.

DevilWah also mentioned that a developer preview release of Java 8 is available which Ross tried and gave the thumbs up to.

This post has instructions of how to get Java 8 installed on your Raspberry Pi, how to get Subsonic working and then how to configure Jukebox mode so that you can play music from the headphone jack or HDMI port of the Raspberry Pi itself.

This post borrows heavily from instructions which are already available on the internet and from Ross’ instructions. I have conglomerated them here as it’s useful to have them all in one place.

I’ve only just completed this build but it does already seem quicker. I’m running the Java 8 Jukebox build on a second Raspberry Pi so will run it side by side with my original build for a while to do some direct comparisons.

Edit: the java 8 version uses a lot less CPU than the open jre used in the original instructions. I’ve just followed these same instructions and directly upgraded my original raspberry pi subsonic server to run on java 8. I have yet to test if the jukebox mode is working on that though.

I should mention that both Pis are the original versions with only 256MB RAM each. I’m running them headless so my only access is through SSH. I have seen a few of the CPU and memory spikes occur on the new Java 8 build in a similar way to the original build but they have not been as severe and have not lasted anywhere near as long. I can also confirm that the Jukebox mode is working as I’ve used it a lot!


So, without Further ado, on with the instructions.

The instructions I followed for installing Java 8 are here and here. Neither gave me the full instructions though so I’ve outlined what I did below.

Java 8 is the first version of the Oracle Java JRE which can run on the faster ‘Hard Float’ version of Debian Wheezy which is available on the Raspberry Pi download pages.

You first job is going to be to set up an SD Card with a fresh image of  Debian. This is explained best on the Raspberry Pi wiki.

Once you’ve booted into your Raspberry Pi via ssh for the first time you should run the config program

sudo raspi-config

The instructions at java.net say that the memory split should be 128MB, so that’s what I did.

The other instruction I followed from java.net which I don’t normally do was to uncomment the two lines in /boot/config.txt.

sudo nano /boot/config.txt


Next up is to download and install Java 8. Follow this link and highlight the radio button to say you accept the License Agreement (it’s standard ‘I promise you my first born’ stuff). Then right click the ‘Oracle JDK 8…’link and select ‘Copy link location’.

Back on your Pi enter wget and then right click on the ssh window and paste. Hit enter and you will start downloading Java 8.

Once it’s finished you need to make a new directory for the install

mkdir -p /opt and then unpack the file you just downloaded into that directory
sudo tar zxvf [file you just downloaded] -C /opt

You now need to tell the system that a new Java version is installed and that you want to use it as default with these commands

sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.8.0/bin/java" 1
sudo update-alternatives --set java /opt/jdk1.8.0/bin/java

The system now knows where Java is installed but we will need to let subsonic know where to find it. To do this we update the JAVA_HOME environment variable which can be set in your environment file.

sudo nano /etc/environment and add the line

You also need to point your bash console to the new environment variable.
nano ~/.bashrc add the lines
export JAVA_HOME="/opt/jdk1.8.0"
export PATH=$PATH:$JAVA_HOME/bin

Give your Pi a quick reboot and you’re all set to install subsonic.

Now we can set up the Jukebox mode so that you can plug your pi into your hi-fi and play music directly on the hardware.
You need to download the Debian .deb package of Subsonic from the Subsonic website
(right click the ‘direct link’ and select ‘copy link as’)

On your pi enter the following command
wget -O subsonic.deb [right click to enter the download url] to download the install package and then
sudo dpkg -i subsonic.deb to install it

We need to create a user for the subsonic process and add that user to the audio group so that jukebox will work
sudo adduser subsonic
sudo adduser subsonic audio

Update subsonic to use this user
sudo nano /etc/default/subsonic and change the last line to

So that subsonic can transcode correctly we install the correct versions of ffmpeg and lame
sudo apt-get install ffmpeg lame

We then add symbolic links to the subsonic transcode folder so that it uses these applications instead of the ones it comes bundled with (good suggestion Ross)
sudo ln -fs /usr/bin/ffmpeg /var/subsonic/transcode
sudo ln -fs /usr/bin/lame /var/subsonic/transcode

We now need to add a line to the coding of subsonic so that it knows that there is a soundcard on the pi and to use that as default
sudo nano /usr/bin/subsonic. find the line that says -verbose:gc \ and add the following line above it
-Djavax.sound.sampled.SourceDataLine=#ALSA \

The last step is to tell the pi which sound output to use. There is a variable in this next command. The last character is ?. You can change this to be one of three values depending on where you want the sound to come from. the available values are:
1 = 3.5mm jack
2 = HDMI port
3 = Default

sudo amixer -c 0 cset numid=3 ?

That’s it! give your pi a reboot and you should now be able to play music directly on your pi.

35 thoughts on “A Raspberry Pi Subsonic Jukebox using Java 8”

  1. good to see its working for you as well.

    I don’t suppose any one has got video trans-coding working have they? for vido streaming to the web player it needs to trans-code to H264 (FLV), and while the Pi should be able to do the encoding in hardware as far as I am aware ffmpeg does not support it.

    I was thinking of setting up my Pi to re-encode all my video library to h264 in the background, but even if i did it this way it would be nice to be able to use the hardware.

    Any one else come across this?

    1. hi DevilWAH.
      Sorry for the delay in replying.

      My video library has been transcoding fine with the standard install of Subsonic. It does occasionally take a while to get going but I haven’t found that any additional steps are needed to get it working.

  2. Mmmm interesting. Mine only seems to transcode at about 8-10 fps. I have the standard ffmpeg settings in transcoding settings. Are you using the SD card as storage or an external drive? I suppose it might be a bottle neck to the USB drive.


  3. Many thanks for this tutorial. I couldn’t get Java 8 to work from the comments of the previous posts, but now it’s working 100%. Using the 3.5mm jack as output, I have a seamless music experience when I come home listening from my Android device when I press the RC button. Very cool!
    Your external harddisk guid also came in handy as I just got a 2TB drive connected to the Pi, containing music, and as backup NAS trough a samba server.

  4. Hi! you got a typo at : “sudo apt-get install ffmepg lame” should be ffmpeg but that’s kinda obvious when it’s spelled correctly at the next command.

  5. Great article and how-to.
    There’s an extra a in Nano for the section of “Update subsonic to use this user”
    Should read sudo nano /etc/default/subsonic.

  6. Would you mind just uploading your SD card image to a file hosting site? (Without any personal configuration, of course.) Since all the hardware is the same, I would assume it would work flawlessly. This would be very helpful for anyone looking to just “plug and play” to get their raspberry pi to be a Subsonic server for music.


    1. Hi Matt,

      If you’re interested in an SD card image I can certainly sort one out and host it. I have not done this before as I had assumed that everyone would be storing their media in different ways so I can’t really have a generic connection to an external drive (for example).
      I’m happy to sort out an image though. I’ll post the link here when it’s up.

      1. It’s possible to have the setup be generic, you just symlink across to /var/music (which is what subsonic expects by default). I do this with my music setup even though it’s actually hosted off external drives.

  7. That would be great. Having a subsonic server to use with my phone when I’m on the go would be an amazing use for my Pi. Thanks!

  8. This is a fantastic guide. Thanks for taking the time to write it up!

    Note that the CPU/GPU memory split of 128 MB isn’t necessary when you’re not running any graphics. I set mine to 16 MB, which makes things run more smoothly and avoids swapping.

  9. Hey, I followed your tutorial to try and get my pi set up for jukebox mode. However, whenever I try to play music(really just access the music files) I get a java.lang.ClassFormatError. It then proceeds to spit out a bunch of java error messages which mean nothing to me. Is this a 1.8 error? Or did I make a mistake on the tutorial? Anyone else having an issue like this?

  10. Alright, I’ve got everything up and running on and sound coming from my 3.5 Jack no problem. I’ve purchased an “approved” dac and am trying to get sound through the USB. What do I need to change in my config files to get sound through the USB DAC? My asound.conf file looks like:
    type hw
    card 1
    device 0

    When I do a speaker-test -c2 -D hw:1,0 I get the left, right sound ok. So, what is the problem with sending sound through USB from Subsonic?

    Thanks for you help folks.

  11. Brilliant guide – I got almost all the way there, but I couldn’t get music through a USB sound card in Jukebox mode. However, using a small bit of Java code to discover what Java thinks my soundcard is called and then modifying Subsonic’s java parameters, I got it working!

    Anyone having problems with USB sound cards and Jukebox mode look at:


    Create a file called audioDevList.java

    Paste in the following:

    import java.io.*;
    import javax.sound.sampled.*;

    public class audioDevList{
    public static void main(String args[]){

    //Get and display a list of
    // available mixers.

    Mixer.Info[] mixerInfo =
    System.out.println(“Available mixers:”);
    for(int cnt = 0; cnt < mixerInfo.length;
    }//end for loop

    Compile with javac audioDevList.java
    Run with java audioDevList

    In the output, you should see something like:
    Available mixers:
    Device [default]
    Device [plughw:0,0]
    ALSA [plughw:1,0]
    Port Device [hw:0]
    Port ALSA [hw:1]

    For me, I wanted "Device [plughw:0,0]" as I had previously set my USB soundcard to be the first/default device (even though Subsonic doesn't seem to respect this!)


    sudo nano /usr/bin/subsonic

    and find the line: -verbose:gc \

    add a line before that one as so:

    '-Djavax.sound.sampled.SourceDataLine=#Device [plughw:0,0]' \

    …but replace Device [plughw:0,0] with the name for your device. NOTE: Keep the # and use the single quotes around the whole argument. Make sure there's a space before the final backslash.

    Restart Subsonic or just reboot and see if that works!

  12. Great guide. Thanks for posting it. I have subsonic up and running on my Raspberry Pi using the latest Raspbian image (2013-09-25-wheezy-raspbian) but I’m having trouble getting jukebox mode to work.

    Here’s the error I’m getting in Subsonic: Error in jukebox: java.lang.IllegalArgumentException: No line matching interface SourceDataLine supporting format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian is supported.

    Any thoughts?

    1. Hi Sean

      It sounds like you’ve not quite got Java pointing at your sound card properly. Can you say a bit more about your setup? Are you trying to use the built in audio on the Pi or a USB sound card? Have you set the -Djavax.sound.sampled.SourceDataLine=xxx line as per the comments above?

      1. Hi Steve. Thanks for helping me troubleshoot this issue.
        I am using the built in soundcard on the Pi. I do have the -Djavax.sound.sambpled.Source.DataLine=xx line in as per the comments. I’ve tried a few different variations of this line: as it was defined in the original post -Djavax.sound.sampled.SourceDataLine=#ALSA \ and the variations you mentioned in your comment using the output from audioDevList.java (the devices being ALSA [default] or ALSA [plughw:0,0] in my case. I’ve tried inserting the line both with and without the surrounding single quotes. I got the same java error in my subsonic log when I tried using jukebox mode in all cases.

        1. Hmm, it sounds like you’re doing the right things. Just a thought… did you add the user under which you’re running subsonic (should be ‘subsonic’ if you followed this guide) to the ‘audio’ group?

          What happens if you try to use aplay to play a WAV file directly using the same device name?

          As an aside – this doesn’t really answer your question – I thought I’d let you know that I went through this pain, only to get it working and then shout “Uggghhhh!!” in disgust at the VERY poor quality of the sound from the built in jack. I would strongly recommend spending a few quid (or dollars) on one of these:


          I plug it straight into the Pi along with an Edimax Wifi dongle and it all runs beautifully and my ears don’t bleed. There is an issue where high volume settings cause distortion, but this is down to less than ideal code in Subsonic itself that causes a positive gain at high slider values. I changed the source and recompiled to fix it.

          Fun all this, eh?

          1. Thanks Steve. I could have sworn I did that before, but maybe I mistyped the command. In any case, I tried the ‘sudo adduser subsonic audio’ command again, and it fixed the problem so I now have sound in Jukebox mode.

            Thanks too, for link to the USB audio device. I may need try one of those in the future.


  13. Nice Guide, worked well 😀
    But I have a problem: Player is working fine, but transcoding is ignoring the bitrate, which is set. It’s everytime transcoding with 192kbps and isn’t caring about what is set. But in the log the bitrate in the ffmpeg command is set correctly.


  14. Excellent guide, But i am having one VERY annoying problem. Music will play perfectly for about 15-25 mins, But then the audio stop for about 1 seconds and then continues playing.

    I am actually using a Hummingboard (Which is 1Ghz dual-core and has 1GB RAM) running raspian, so it’s not a hardware limitation as it also did it on my B+ pi. Maybe something with ffmpeg? any ideas?

    Thank you!

  15. I tried to do this, but I get an error trying to unpack Java 8 (not a gzip file). Ignoring this I tried to do a (clean) install of Subsonic, but after a succesful download, I cannot install the programme and get the message:
    “Cannot access archive: No such file or directory”

  16. Thank you very much for this wonderful tutorial, so generous of you to have made it – and made it so good. I tried several others and got lost, but yours is exceptional well done.

    I had one little hiccup, the version of java you suggested (and that link) seemed to give me a corrupt file. I downloaded it elsewhere, so i don’t know if that was my fault of the depository’s fault. Just in case anyone comes up against that issue.

    Anyway, you’ve made me love my Raspberry Pi, The internet, and humanity even more!

    1. Thanks for the kind words Lake. The tutorial was written when Java 8 had only just been released. I believe that java 8 is now available as standard on the raspbian image for the Raspberry Pi. You can check this on a fresh raspbian install by typing java -version on the command line.

  17. Thank you for this guide!! I’m trying to install subsonic on my Pi 2 but I’m struggling with HTTP ERROR 503 when I try to connect to the ip:4040…. by the way on my Pi2 the audio interfaces are

    0 = Auto
    1 = 3.5mm jack
    2 = HDMI port

    and you can change them using raspi-config 🙂

  18. Just a word of warning, right clicking and copying either java or the subsonic.deb download file won’t actually give you the download link. So using that with wget you’ll just get a text file particularly with Java.

    I had to download it on my PC and transfer it to the Pi’s SD card manually, same with subsonic.deb file.

  19. Hello and many thanks for an awesome guide! It really helped me to get Subsonic Jukebox working on Raspberry Pi Zero.

    But it is 2016 now and some things have changed. Because of that, I would like to try, to sum up, all the steps I have done differently.

    Disclaimer: I use Raspberry Pi Zero and [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) as a headless Subsonic Jukebox system connected to my Creative X-Fi HD sound card connected via USB. I control it remotely with [DSub](https://play.google.com/store/apps/details?id=github.daneren2005.dsub).

    ## Boot config
    As RPi Zero does not have much of HW resources, I did change the split to 16MB. ([as mentioned in the comments](https://mj2p.co.uk/a-raspberry-pi-subsonic-jukebox-using-java-8/#comment-84))

    pi$`sudo vi /boot/config.txt`

    Add the following line of code at the end of the file.


    I did not uncomment the framebuffer.

    ## Installing Java
    – it is now extremely easy ([source](https://wolfpaulus.com/journal/software/tomcat-jessie/))

    pi$`sudo su`

    pi#`echo “deb http://ppa.launchpad.net/webupd8team java/ubuntu trusty main” > /etc/apt/sources.list.d/webupd8team-java.list`

    pi#`echo “deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main” >> /etc/apt/sources.list.d/webupd8team-java.list`

    pi#`apt-key adv –keyserver keyserver.ubuntu.com –recv-keys EEA14886`

    pi#`apt-get update`

    pi#`apt-get install oracle-java8-installer`

    pi#`java -version`


    ## Install Subsonic
    I did follow the post in this one.
    Install, create a user, add him to the audio group, set a password `passwd subsonic` and set him as a default Subsonic user.

    But here is a little problem. `ffmpeg` is not available in Raspbian Jessie. But there is `avconv` which is a fork of `ffmpeg`, so all the parameters used with `ffmpeg` work fine. `avconv` is in the `libdav-tools` package.

    pi$`sudo apt-get install libdav-tools lame`

    To save yourself from changing the `ffmpeg` command to `avconv` in Subsonic, I did this with links. Not sure if this is the right way, though.

    pi$`sudo ln -fs /usr/bin/avconv /var/subsonic/transcode/ffmpeg`
    pi$`sudo ln -fs /usr/bin/lame /var/subsonic/transcode`

    ## Set up sound card
    [This comment explains it all. Amazing work.](https://mj2p.co.uk/a-raspberry-pi-subsonic-jukebox-using-java-8/#comment-92)

    Mine was
    `’-Djavax.sound.sampled.SourceDataLine=#HD [plughw:1,0]’ \`

    With no need to use the `amixer` command mentioned in the post. If you are going to use the HDMI or jack, then you may need it. I do not know.

    ## Last touch
    Before running Subsonic, I created library folder and changed some permissions.

    pi$`sudo mkdir /var/music`
    pi$`sudo chown -R subsonic:subsonic /var/music`
    I **do not know** if this step is needed, but I think it solved one of my problems.
    pi$`sudo chown -R subsonic:subsonic /var/subsonic`

    ## Dance!
    pi$`sudo reboot`
    pi$`su subsonic`

    The web interface will be up and running after few minutes 🙂 the Zero is quite lazy. Remember to set the Jukebox mode if you want it in `Settings > Players`. No other changes were necessary. I am testing it right now with a library either on my USB flash card or an SD card. So setting the connection to your library is on to you. I tested it on a podcast and it works fine. The web interface is quite painful to use on the Zero, but controlling it with DSub Android app is ok. Playing FLAC files without a problem.

    1. Thank you for this… I could not get transcoding to work on the Raspberry Pi running Raspbian Jessie. This part helped with that:

      pi$`sudo apt-get install libdav-tools lame`

      To save yourself from changing the `ffmpeg` command to `avconv` in Subsonic, I did this with links. Not sure if this is the right way, though.

      pi$`sudo ln -fs /usr/bin/avconv /var/subsonic/transcode/ffmpeg`
      pi$`sudo ln -fs /usr/bin/lame /var/subsonic/transcode`

      just one change, the package is libav (no d) so run:

      pi$`sudo apt-get install libav-tools lame`

Leave a Reply

Your email address will not be published. Required fields are marked *