Streaming Internet Audio Using Mplayer

From MythTV Official Wiki
Jump to: navigation, search

This article is to provide information on how to integrate Internet Radio into Mythtv. This is based on Fm radio but I wanted to post details on how to make it work for Internet Radio too.


Important.png Note: this is NOT a plug-in and is basically a hack but when completed it looks just like a plug-in.


Article from 10,000 feet

What this article is...

This article IS about:

  • Setting up Myth to play streams via Mplayer
  • How-To use programs that other people wrote (and are not affiliated with MythTV)
  • How-To integrate everything with the default MythTV menu theme

What this article is not...

This article IS NOT:

  • How-To perfectly integrate with your particular MythTV GUI (we only cover the default menu theme)
  • A Streaming Plug-in for MythTV

What is required

A working installation of MythTV and mplayer are required Also, for on screen display, a copy of ocd_cat (part of XOSD) is required (http://ignavus.net/software.html)

Hacking it together

OK, now we are going to write a couple of über-simple shell scripts that we will use to make MythTV work with mlayer. You will notice that these are simple, novice scripts that are pretty crude. This hasn't been called it a "hack" for nothing.

Create files

We need to create a couple of files so find a nice place you can create and execute them from. Personally, I put them in ~/.mythtv

# vi inetradio
#!/bin/sh

## Play Internet Radio Streams on MythtV

if [ "$1" = "gs" ]; then
        killall mplayer
        killall osd_cat
        echo "Streaming Groove Salad" | osd_cat -w -p bottom -A center -d 100 -l 1 -c white  -f -adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1 -s 2 -o 70&
        mplayer -nolirc http://somafm.com/startstream=groovesalad.pls&

elif [ "$1" = "sa" ]; then
        killall mplayer
        killall osd_cat
        echo "Streaming Secret Agent" | osd_cat -w -p bottom  -A center -d 100 -l 1 -c white  -f -adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1 -s 2 -o 70&
        mplayer -nolirc http://somafm.com/startstream=secretagent.pls&

elif [ "$1" = "xm" ]; then
        killall mplayer
        killall osd_cat
        echo "Streaming Christmas Lounge" | osd_cat -w -p bottom -A center -d 100 -l 1 -c white  -f -adobe-helvetica-bold-r-normal--34-240-100-100-p-182-iso8859-1 -s 2 -o 70&
        mplayer -nolirc http://somafm.com/startstream=christmas.pls&

elif [ "$1" = "kill" ]; then
        killall mplayer
        killall osd_cat
else
        exit 1
fi

Odiously you are going to want to change the stations here

Now you will want to make this executable:

# chmod a+x inetradio

You also might need to change the font cal out by the osd_cat program. You can get a list of fonts installed on your system with this command:

$ xlsfonts

Test scripts

Now, pull up a command window and run one of the commands we just "made"

$ ./inetradio sa

Did you hear your stream?

Setting up the MythTV GUI

At this point, you should be able to play your streams from the command line with no user intervention... that's 1/2 the battle. Now, we are going to hack a couple of buttons onto the default menu theme.


Important.png Note: If you are currently running MythTV version 0.20 or higher chances are that you're using the default menu theme. No, not the actual MythTV theme, just the menu theme. To check out which one you're using do this in Myth: Utilities / Setup (or Setup) -> Setup -> Appearance -> and at the bottom of the first options page you will see the menu themes selection box, we will be hacking into "Default" so make sure it's set to that one. If you use classic or DVR you can change some of the commands below so that your work is being done on that particular theme (just add /themes/classic or /themes/DVR respectively to the "cd" commands below).

Backup the default theme

# cd /usr/share/mythtv/themes/defaultmenu
# tar cfvz default_backup.tar.gz *.xml

I use the v option because it's an easy way to verify (VIA verbose) what files were put into the tar ball.

Hack the default theme

I'm only going to show you the 2 required changes to get this hack to work.

I added the following to my library.xml file.

# cd /usr/share/mythtv/themes/defaultmenu
# vi library.xml
<pre>
   <button>
     <type>FM</type>
     <text>Internet radio</text>
     <action>MENU inetradio.xml</action>
   </button>

Then, I created the inetradio.xml file (be sure to add all of the stations you want access to):

# vi inetradio.xml
<mythmenu name="INETRADIOMENU">

   <button>
      <type>INETRADIO</type>
      <text>SomaFM Groove Salad</text>
      <action>EXEC ~/.mythtv/inetradio gs</action>
   </button>

   <button>
      <type>INETRADIO</type>
      <text>SomaFM Secret Agent</text>
      <action>EXEC ~/.mythtv/inetradio sa</action>
   </button>

   <button>
      <type>INETRADIO</type>
      <text>SomaFM Xmas Lounge</text>
      <action>EXEC ~/.mythtv/inetradio xm</action>
   </button>

   <button>
      <type>TV_DELETE</type>
      <text>Stop Listening</text>
      <action>EXEC ~/.mythtv/inetradio kill</action>
   </button>


</mythmenu>

Tag definitions

OK, now the tag definitions for the above xml file

  • "button" tells the theme to paint a button on the screen
  • "type" tells the theme what image to use for the button
  • "text" tells MythTV what button text to put on the screen
  • "action" tells MythTV what to do when you select the button

Additional Setup and Usage Notes

Screen shots