Nicecast And The Web

If you've created a Nicecast audio stream, you probably want to get listeners for it. The quickest way to do this is to turn on the "List on MacStreams.com" option in the Share drawer. This will upload information about your stream (as set in the Info drawer) to the MacStreams.com directory, visible to the world. But if you've got your own website, you can also use that to promote your stream.

Linking To Your Stream
If you just want to create a simple text link to your stream, just pull the address from the Share drawer, as found in next to the Internet setting. For example, if the address to the audio stream is http://www.example.com:8000/playlist.pls, the following HTML is used to create a link:

<a href="http://www.example.com:8000/playlist.pls">Click To Tune In</a>

On Air Test
You may also like to display information on the On Air status of the stream. In order to display dynamic information on your website, you'll need to use something like PHP. The example below uses a simple PHP function, and basic HTML. If you don't know anything about PHP, now's the time to learn. Grab a book or check out the PHP.net. Please note, we can't teach you PHP, and the below is merely provided to aid you.

PHP Function:

function onAirTest($ipaddress, $port)
{
   if ($ret = @fsockopen($ipaddress, $port, $errno, $errstr, 1))
   {
      fclose($ret);
      return true;
   }
   
   else
   {
      return false;
   }
}

Once this function is available (by sticking it at the top of the page, or in a PHP functions file for your site), it can be combined with a simple if/else statement as follows. Be sure to adjust the address (WWW.EXAMPLE.COM) and the name (MY STATION) as need. This setup can also be spruced up with graphics and alternate text as desired.


if (onAirTest("WWW.EXAMPLE.COM", "8000"))
{
   print "MY STATION Is Currently On The Air";
}
else
{
   print "MY STATION Is Currently Off The Air";
}

Now Playing Info
Finally, you may wish to display the title of the currently playing track, as well as previously played tracks.

If you're using iTunes as your source, there are several applications in existence to help publish this information. Two oft-used tools are Kung-Tunes and the japanese Now Playing. Download these utilities and give them a try.

To do this without other tools, you'll need to use the Recent Tracks Log (RTL) file (as seen in the Preferences window), coupled with PHP. Again, if you don't know anything about PHP, grab a book or check out the PHP.net. And as before, please note that we can't teach you PHP, and the information below is merely provided to assist you.

If you're running both your Nicecast server and your web server on your local machine, this is fairly easy. You just need to save the RTL file to somewhere in your web directory, and then access it. The following code opens the rtl.txt file, reads in the first line to the $buffer variable, and prints it out after the "Current Track:" text

$fp = fopen ("music/rtl.txt","r");
if (!feof($fp) )
{
   $buffer = fgets($fp, 1024);
   print "<tr><td align=\"center\"><b>Current Track</b>: $buffer";
}

fclose ($fp);

If you're using a remote web server, you'll need to find a way to get the RTL file up to that web server before it can be read. This is more difficult, and will likely require some sort of scripting. Research in AppleScript and other solutions will likely be the best bet. Good luck!

Embedding Content In A Webpage
It's possible to embed a stream in a webpage, with the following code. First, you need to create a custom .m3u file with an icy:// URL. To do this, make a new file in TextEdit called "listen.m3u" and put a single line in it as follows:

icy://www.example.com:8000/listen

Replace "www.example.com:8000" with the proper address and port of your server, which you can get next to the Internet label in the Share drawer in Nicecast. Choose Make Plain Text from the Format menu in TextEdit, then save this file as listen.m3u. TextEdit may warn about the file extension - be sure to choose Use .m3u.

Once you've got the file created, upload this file to your web server in the same directory as the web page where you want to embed the stream. When you've done that, you're ready to edit your web page. Insert the following HTML in your page where you want the stream controller to be displayed:

<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" HEIGHT="16" WIDTH="160">
<PARAM NAME="src" value="listen.m3u">
<PARAM NAME="qtsrc" value="listen.m3u">
<PARAM NAME="type" value="video/quicktime">
<PARAM NAME="autoplay" value="false">
<PARAM NAME="controller" value="true">
<EMBED PLUGINSPAGE="http://www.apple.com/quicktime/download/"
   SRC="listen.m3u"
   QTSRC="listen.m3u"
   TYPE="video/quicktime"
   WIDTH="160"
   HEIGHT="16"
   SCALE="tofit"
   CONTROLLER="true"
   AUTOPLAY="false"
   KIOSKMODE="false">
</OBJECT>

This points the QuickTime Plugin in each browser to the custom .m3u file, which in turn points to your Nicecast stream in the way that QuickTime expects.