Show current track title on a web site

Status
Not open for further replies.

djsoft

Well-known member
Staff member
A new script is available: https://www.djsoft.net/smf/index.php/topic,6352.0.html



Guide: how to show playing track title on a web page.

Quick Setup:
1. Download the attached track_title.zip file and put its contents to your web site's root folder.
2. Open RadioBOSS, open Settings->Reports/Now playing
3. Add a new HTTP request, enter URL: http://your-web-site.com/httpreq.php?artist=%artist&title=%title and click OK.
4. Check the "Use HTTP request" option, click OK.

Testing:
Start any track in the playlist and visit http://your-web-site.com/showtitle.htm - track title should be displayed on the web page.
To display title on a custom web page, copy-paste the code contained between <!-- begin update track title code --> and <!-- end update track title code --> tags from showtitle.htm.

Manual setup without using the supplied .zip archive:
1) First of all you'll need a script to receive info from RadioBOSS. Create it and upload it onto your web site. In this example the script is called httpreq.php
Script source code:
Code:
<?php
	//get artist/title info
	$artist = $_GET['artist'];
	$title = $_GET['title'];
	
	//create a temp file to store values for AJAX script
	$r = fopen("temp_title.txt", "w");
	fwrite($r, $artist." - ".$title);
	fclose($r);
?>
When RadioBOSS calls this script via HTTP Request feature, it will create temp_title.txt file where track information is stored.
* if file is not created, create it with any FTP client and set its rights to 777.

2) In RadioBOSS open Settings->Reports, check "Use HTTP request" option, click "+" to add new request and enter URL of your script and request parameters. For example:
Code:
http://example.com/httpreq.php?artist=%artist&title=%title
As you see it sends %artist and %title information.
More about HTTP request and its parameters: http://manual.djsoft.net/radioboss/en/http_request.htm

3) Web page example to show track information - title.html:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
	<b>Here you'll see track title:</b>

	<!-- begin update track title code -->
	<div id="track_name"></div>
	
	<script type="text/javascript">
		function UpdateTitle()
		{ 
			var xmlhttp;
			//get "track name" block
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp = new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
			  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
				{
					var s = xmlhttp.responseText;
					document.getElementById('track_name').innerHTML = s;
				}
			}
			//use random number in request to prevent caching
			var rand_no = Math.random();
			rand_no = rand_no * 100;
			//read the "temp_title.txt" file
			xmlhttp.open("POST", "/temp_title.txt?"+rand_no, true);
			xmlhttp.send();		
		}	
		//
		setInterval("UpdateTitle()", 1000);
		UpdateTitle();
	</script>
	<!-- end update track title code -->
	
</body>
</html>
It just reads the temp_title.txt file and shows this info on a page. Title is updated every 1000ms (1 second). Track title updated without page reload.
 

Attachments

  • track_title.zip
    1.3 KB · Views: 1,575
I've set up for live streaming from my PC hard drive using the Icecast2 file. I followed the instructions for Play information and the httpreq talks to the the temp_title.txt file just fine however I get an error in the RB player saying the HTTP Request is denied.

My question is... Is this because I'm streaming from my PC or am I doing something wrong? Do the files have to be in a root folder or will it work with a sub folder and I did change all the links accordingly to direct to the sub folder.

Thanks
 
I figured it out!!!  :D

I had to use the FTP config and in the directory box I had to use the root address not the web.

Works great now thank you
 
BigMarkess said:
I had to use the FTP config and in the directory box I had to use the root address not the web.

Works great now thank you
Yes, the paths depend on FTP server you're using, I'm glad you've sorted this out :)
 
If I could pass the cover URL to that, which is already in the comments of the MP3 metadata, that would be cool.
 
johngrant said:
If I could pass the cover URL to that, which is already in the comments of the MP3 metadata, that would be cool.
Those are the custom scripts on your web site - you can pass the comment and then use it as cover URL to display artwork.
 
I had an issue with the hosting site because temp_title.txt got an enormous number of hits, 10x the next most requested file.  The host suspended the account.  Any circumstances where the script could loop and make an excessive number of hits on that file?  Thanks.
 
johngrant said:
I had an issue with the hosting site because temp_title.txt got an enormous number of hits, 10x the next most requested file.  The host suspended the account.  Any circumstances where the script could loop and make an excessive number of hits on that file?  Thanks.
I don't think so - the script included in the first post makes a request every second. Maybe your host considers it as "too many hits". Eg. if you have 10 users who are viewing your web site, there'll be 600 requests every minute. You can increase the timer interval so it'll update eg. every 5 seconds.
Better solution would be to change the host of course.
 
jopara said:
Hello, is it also possible to show the album cover?
RadioBOSS can upload cover art to FTP: http://manual.djsoft.net/radioboss/en/log_files___reports.htm
You can then display it on your web site.
 
Hi. Currently I have changed my websites to the Vesta control panel. Before Cpanel had Show current track title on a web site but since that change is not shown. Any ideas? Thank you
 
It could be the rights issue - the script can't write to some file. I suggest you to review that all steps listed in the first post are performed.
 
You are right. Effectively the file permissions on the server are at 777.
Everything was going perfectly. It has been when switching from control panel from Cpanel to VestaCP.
Will some configuration in the latter be necessary for it to work?
It's all very weird, it's just a script, right?
Thank you
 
jopara said:
Everything was going perfectly. It has been when switching from control panel from Cpanel to VestaCP.
Will some configuration in the latter be necessary for it to work?
I don't think so - as you can see in the script sources, it's very simple. However, it could be that control panel has some limitations for PHP and therefore it doesn't work. I can't help you with it as it's not a problem with the script itself, it's something to do with server configuration. I suggest you to check the logs, it usually provides some clues on why it doesn't function properly.
 
RadioBOSS can upload cover art to FTP: http://manual.djsoft.net/radioboss/en/log_files___reports.htm
You can then display it on your web site.

Ok, but what script should be used to show the cover on my website?
 
jopara said:
RadioBOSS can upload cover art to FTP: http://manual.djsoft.net/radioboss/en/log_files___reports.htm
You can then display it on your web site.

Ok, but what script should be used to show the cover on my website?
Currently we don't have an example script to do that.
 
My apologies for bumping the thread, but I do have a related question. Suppose I wanted to do this but have a live list of the current song playing plus the last 10 songs to play (similar to this). Is this possible? If so, how would I do this?

Thanks for any help you may be able to provide!
 
One option is to keep the list of played tracks on your web site. Another option is to use the RadioBOSS API and etrieve the list of last played songs using the getlastplayed command: https://manual.djsoft.net/radioboss/en/remote_controlapi.htm
 
Hi there. I've managed to get current track displayed. Any ideas how to show "next track" on my website? Thank you
 
zacgu said:
Hi there. I've managed to get current track displayed. Any ideas how to show "next track" on my website? Thank you
We'll release an updated nowplaying script soon that will show how to do it.
 
Status
Not open for further replies.
Back
Top