Sunday, April 3, 2011

Streaming internet radio with MythTV

Streaming internet radio with mythtv is, sadly, still confined to the realm of hacks. One simple solution is to just drop ".pls" files into your videos directory. Assuming you use mplayer to play your videos, that should just work. Unfortunately I like to use the internal player so I can use the time stretch feature on videos as well as recordings. The internal player doesn't play ".pls" files, so that option is out.

The other approach is to hack in a new menu item and get it to run mplayer. There are a few descriptions of how to do this, so here is my 2c.

Edit /usr/share/mythtv/themes/defaultmenu/library.xml to add:

<button>
    <type>MUSIC_RADIO</type>
    <text>Listen to Internet Radio</text>
    <description>Listen to Internet Radio</description>
    <action>MENU inetradio.xml</action>
    <depends>mythmusic</depends>
</button>

And create inetradio.xml in the same directory.  The Australian Broadcasting Corporation (ABC) links are a little hard to find - you can get them here.
<mythmenu name="INETRADIO">

<button>
<type>MUSIC_PLAY</type>
<text>NPR</text>
<action>EXEC /usr/bin/mythradio http://npr.ic.llnwd.net/stream/npr_live24</action>
</button>

<button>
<type>MUSIC_PLAY</type>
<text>TripleJ</text>
<action>EXEC /usr/bin/mythradio http://www.abc.net.au/res/streaming/audio/aac/triplej.pls</action>
</button>

<button>
<type>MUSIC_PLAY</type>
<text>RawFM</text>
<action>EXEC /usr/bin/mythradio http://www.rawfm.com.au/stream/playlists/160kbitMP3.pls</action>
</button>

<button>
<type>MUSIC_PLAY</type>
<text>666 ABC Canberra</text>
<action>EXEC /usr/bin/mythradio http://www.abc.net.au/res/streaming/audio/aac/local_canberra.pls</action>
</button>

<button>
<type>MUSIC_PLAY</type>
<text>ABC Classic FM</text>
<action>EXEC /usr/bin/mythradio http://www.abc.net.au/res/streaming/audio/aac/classic_fm.pls</action>
</button>

<button>
<type>MUSIC_PLAY</type>
<text>Stop Playing</text>
<action>EXEC pkill -f mplayer</action>
</button>

</mythmenu>

And create /usr/bin/mythradio (this wouldn't be necessary if you could give multiple commands to "EXEC" - unfortunately it seems to break the syntax and mythtv says it is an invalid XML file). The include file is a one line mplayer config that tells mplayer to allow the screensaver to run, so you can avoid burn-in while listening to the radio.

#!/bin/bash
pkill -f mplayer
/usr/bin/mplayer -include /etc/mythtv/mplayer_noscr.conf $1 &

and here is /etc/mythtv/mplayer_noscr.conf:

stop-xscreensaver=no

3 comments:

Tim said...

I had to replace http with mmsh in each link for stream to work

Joe said...

You rock my friend!!! Best explanation on how to setup streaming audio on MythTV Now if someone would write a proper plugin, that would be great!

Unknown said...

Just found this - wanted to run an MPD server within the mythtv server and play the stream from Mythtv (poor man's Sonos across the house..)

Gave me good pointers but found I had to hard code the server address etc into mythradio script (not found out why yet...)

Thankd for the pointers!