I recently had a trial of Spotify and I liked it. I’m not ashamed to admit it. I thought about signing up fully with them until I thought a little harder about it…What if I decide to cancel at some point in the future? That means I have no more access to any music post Spotify signup. What about all of the tracks that aren’t on Spotify?

In addition, I like to dabble in music production and I like to listen to cuts of music whilst I’m working on it. Spotify can’t cater for this. Extra users are more expensive again and my wife is interested in a system like this too.

With this in mind, I figured that I should look into hosting my own music and allowing it to be streamed by me and my family.

After some reading, I settled on Airsonic as it was open source, and it had recent active development. Also, there appeared to be lots of supporting players.

Next I had to settle on a way to host it. Of course I was going to start with a raspberry pi but, luckily for me, I had a kodi instance already running on a pi3. This instance had all of my music already via a big old hard drive and it is an OSMC install.

If you want to follow my route you can find out about installing OSMC via osmc.tv. You can follow along if you have a different kodi install, or even if you’re installing on a clean pi setup. All you’ll need to do is get your pi access to your music. I prefer the idea of the hard drive being atached to the pi for the sake of speed of access.

Getting started and backing up

Update your OSMC via it’s GUI or update via sudo apt-get update I decided to backup my OSMC image here using ApplePi-Baker, but I’m sure you have your own ways of creating backup images of SD cards so I won’t go into detail here.

If you’re using a build that doesn’t have oracle java in it’s repos (OSMC for example like me) you are best to download and install Java manually:

  • Download the java 32 bit ARM jdk from:

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

  • Upload the file to osmc via ftp or scp

  • Unzip the file

      tar -xvf <java-file-downloaded>
    
  • Move the JRE into place and fix updates

      sudo mv <jdk_extract_dir>/jre/ /opt/
      sudo update-alternatives --install /usr/bin/java java /opt/jre/bin/java 100
    
  • Test java -version it should display:

      Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
      Java HotSpot(TM) Client VM (build 25.181-b13, mixed mode)
    

01 java install

  • Install tomcat (this will take a little while):

      sudo apt install tomcat8
    
  • Open the tomcat8 config:

      sudo vi /etc/default/tomcat8
    
  • Add the following line and save:

      JAVA_HOME=/opt/jre
    

02 update tomcat config

  • Download and install airsonic:

      wget https://github.com/airsonic/airsonic/releases/download/v10.1.2/airsonic.war
      sudo mkdir /var/airsonic/
      sudo chown -R tomcat8:tomcat8 /var/airsonic/
      sudo systemctl stop tomcat8.service
    
  • If you have a previous version of Airsonic install, run the following:

      sudo rm /var/lib/tomcat8/webapps/airsonic.war
      sudo rm -R /var/lib/tomcat8/webapps/airsonic/
      sudo rm -R /var/lib/tomcat8/work/*
    
  • Move the airsonic war file into place:

      sudo mv airsonic.war /var/lib/tomcat8/webapps/airsonic.war
    

I required a tomcat port change as 8080 is already in use by OSMC on my system. If you require it too use the following method:

    sudo vi /etc/tomcat8/server.xml
  • Replace all instances of 8080 with 8081 or an equivalent port:

  • Restart the tomcat server:

      sudo systemctl start tomcat8.service
    

This takes a while again, wait around serveral minutes and then open the following in a browser:

    http://<your-osmc-ip>:<your-port>/airsonic 

03 airsonic login

  • Login with admin:admin

  • Follow the first step link and change your administrator user and pass.

04 airsonic welcome screen

  • Follow the second step link and set up your media folders

05 directory set up

Transcoding:

My system didn’t have ffmpeg installed by default, if yours doesn’t, follow the below method:

  • Install ffmpeg:

      sudo apt-get install ffmpeg
    
  • Create a symbolic link to the transcode directory of airsonic:

      sudo ln -s $(which ffmpeg) /var/airsonic/transcode/
    
  • Change the ownership to the tomcat8 user:

      chown -h tomcat8:tomcat8 ffmpeg
    

This should now be set up for use with airsonic as you have linked it up via the symbollic link.

Open it up for streaming

At this point you can access airsonic at http://<your-ip>:<your-port>/airsonic but I wanted to allow access to mine from outside of the network. This is where nginx comes in. My personal setup has a gateway pi that controls this kind of thing along with duckdns.

I have already covered setting up nginx and duckdns usage in previous posts so I won’t go over them again here.

The config that I used for nginx is as follows:

    location /airsonic/ {
            proxy_pass http://<your-ip>:<your-port>/airsonic/;
    }

I added it to my main dynamic dns domain configuration that is already port forwarding from my gateway pi.

After a quick nginx restart, I can now access airsonic from outside my network.

Apps for usage:

I am currently using https://www.clementine-player.org/ as a desktop application and I’m using https://play.google.com/store/apps/details?id=net.sourceforge.subsonic.androidapp as my phone application.

06 clementine