Using Pandora & Adding Remote Control - Part 6

To start up Pianobar, just type:

pianobar

and it should start loading and look like below. From here the controls are described on screen, on how to use it.


Sound Card Notification Problem
I had a problem with it announcing which sound card it was using every time it changed a song. To fix this, we have to edit another file to stop this from displaying.

So (q) quit out of Pianobar and back at the terminal prompt, we need to type:

sudo cp /usr/share/alsa/alsa.conf /usr/share/alsa/alsa.conf.bak

This will make a backup of the sound config file. Then:

sudo nano /usr/share/alsa/alsa.conf

Using Nano to open up the file and we need to find a line of script that looks like this:

pcm.front cards.pcm.front

Its mid-way in the file. Change it to this

pcm.front cards.pcm.default

This should remove that notification.

Run Pianobar again and it should be now playing properly.

Adding Remote Control

Now that we have Pianobar working properly and how we want, we now want the ability to control it from your phone or tablet.

Before we start with the scripts that are needed for pi to be controlled remotely, lets install the app to your phone or tablet.

Install App from Google Play Store
Using your phone or tablet, and using android, search for the app in the play store called, Pianobar (Pandora) Remote.





(I think that this app is only available on some android devices, depending on size of the screen as well.)

Configuring App to Connect to Your PI
With the App downloaded, we can set it up, even if the Pi is not ready yet.

First off, we need to add a profile for login to your pi remotely. On your android, tap on the menu button on the left of the home button. You should have a list of option come up, with 'Add new Server'.

From here, add in a name, IP address, username (pi), password (raspberry) and port number (22).

Click on save for that profile and a new link will be added for that server. We wont be able to use it just yet, as we have to install the remote software first. But its good to have it ready.

Remote Script for Pianobar

We will be using a remote control script written but a user name azeam over at the raspberry pi forums.
Forum discussion here

Following his instructions on installing the remote we need to:

(Make sure you have rebooted before starting this.)

Changing the Pianobar config
Adding an extra line to the pianobar config file:

Backup the main config file before changing it.

sudo cp .config/pianobar/config .config/pianobar/config.bak

and now we open the config file with nano

sudo nano .config/pianobar/config

inside the file find the line:

#event_command = /home/pi/.config/pianobar/scripts/eventcmd.sh
and change it to:

event_command = /home/pi/.config/pianobar/eventcommand.sh

Quit out (ctl &x) and save it (y and enter). Now we need to create the file eventcommand.sh

Create the Eventcommand.sh file
This part is easy. We have to create the file first:

sudo nano .config/pianobar/eventcommand.sh

Then add in the latest script from azeams forum page:

#!/bin/bash

fold="$HOME/.config/pianobar"
stl="$fold/stationlist"
ctlf="$fold/ctl"
nowplaying="$fold/nowplaying"
while read L; do
        k="`echo "$L" | cut -d '=' -f 1`"
        v="`echo "$L" | cut -d '=' -f 2`"
        export "$k=$v"
done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|songDuration\|songPlayed\|coverArt\|stationCount\|station[0-9]\+\)=' /dev/stdin)

case "$1" in
        songstart)
        echo -e "$artist \n$title \n$stationName \n$rating \n$coverArt \n$album" > "$nowplaying"
;;
   songlove)
        echo -e "$artist \n$title \n$stationName \n$rating \n$coverArt \n$album" > "$nowplaying"
;;
   songban)
   echo -e "" > "$nowplaing"
;;
   
    usergetstations)
      if [[ $stationCount -gt 0 ]]; then
        rm -f "$stl"
        for stnum in $(seq 0 $(($stationCount-1))); do
          echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
        done
      fi

      ;;
      stationcreate)
           if [[ $stationCount -gt 0 ]]; then
                  rm -f "$stl"
                  for stnum in $(seq 0 $(($stationCount-1))); do
                         echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
                  done
           fi

           ;;
   stationaddgenre)
         if [[ $stationCount -gt 0 ]]; then
                  rm -f "$stl"
                  for stnum in $(seq 0 $(($stationCount-1))); do
                         echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
                  done
           fi

           ;;
   songexplain)
          if [[ $stationCount -gt 0 ]]; then
                  rm -f "$stl"
                  for stnum in $(seq 0 $(($stationCount-1))); do
                         echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
                  done
           fi

           ;;
           stationaddshared)
          if [[ $stationCount -gt 0 ]]; then
                  rm -f "$stl"
                  for stnum in $(seq 0 $(($stationCount-1))); do
                         echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
                  done
           fi

           ;;
        stationdelete)
           if [[ $stationCount -gt 0 ]]; then
                  rm -f "$stl"
                  for stnum in $(seq 0 $(($stationCount-1))); do
                         echo "$stnum) "$(eval "echo \$station$stnum") >> "$stl"
                  done
           fi
      echo -e "" > "$nowplaying"
           ;;
esac


And then quit out (ctl &x) and save it (y and enter).

We then make it an executable:

sudo chmod +x .config/pianobar/eventcommand.sh

and then make another file to receive commands:

sudo mkfifo .config/pianobar/ctl


At this point, I found a problem that others in the forum had also, with it not accepting command from the Andriod App that I installed on my phone. It started to say that it could not collect the stations from the Pandora service, and that Pianobar had stopped working.

As it turns out, the permissions for the folder and the files within the pianobar directory are set to the Root user (or the super admin for your raspberry), and not the default user that we login in to, which is pi.

So what I had to do is change the owner of Pianobar over to my login which is pi. I used the following command to change owner of all files and folders within Pianobar to the pi user.

sudo chown -R pi:pi .config/pianobar

This will now allow you to access the pi, and access your list of stations that you use in Pandora.

Done! :)

Comments

Popular posts from this blog

Configuring Allied Telesis Switches with PuTTy

FASTER - Arma 3 Server Manager (#Arma3_DIYDGS) Part 1

#DIYDGS - The Basics - Learning Steam_CMD