Jump to content

Hi all. I am trying to make a website with my raspberry pi b+. The website will basically play song after song all day and be accessible from anywhere. For example my friend wants to chill out and listen to some random music. He would goto the website and it would play random songs from a hard drive. Any way to do this?

I like pie.

Link to comment
https://linustechtips.com/topic/873384-website-radio/
Share on other sites

Link to post
Share on other sites

You'll need the hard drive plugged into the pi (obviously) and the folder containing the songs get mounted somewhere in your webroot (/var/www/) folder.

 

You'll then need a PHP file to return a random song file name from the folder, a HTML file containing an <audio> element, and javascript code which waits until the <audio> element has finished playing.

 

When the page first loads, the javascript code then launches an ajax request to the PHP file, which will read the entire directory containing the songs and return the relative path of a random song. The javascript code then changes the src (currently playing track) in the <audio> element, then plays it. When it finishes playing, the javascript code launches the ajax request again and the cycle continues indefinitely.

 

The obvious problems with this would be that the same song might play more than once, but that could be solved by having an array (in javascript, not the php code) store all the songs that have played since the webpage loaded, and if those songs get returned by the PHP script, it ignores it and performs an ajax request for another random song.

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10823974
Share on other sites

Link to post
Share on other sites

3 hours ago, burnttoastnice said:

You'll need the hard drive plugged into the pi (obviously) and the folder containing the songs get mounted somewhere in your webroot (/var/www/) folder.

 

You'll then need a PHP file to return a random song file name from the folder, a HTML file containing an <audio> element, and javascript code which waits until the <audio> element has finished playing.

 

When the page first loads, the javascript code then launches an ajax request to the PHP file, which will read the entire directory containing the songs and return the relative path of a random song. The javascript code then changes the src (currently playing track) in the <audio> element, then plays it. When it finishes playing, the javascript code launches the ajax request again and the cycle continues indefinitely.

 

The obvious problems with this would be that the same song might play more than once, but that could be solved by having an array (in javascript, not the php code) store all the songs that have played since the webpage loaded, and if those songs get returned by the PHP script, it ignores it and performs an ajax request for another random song.

Is there a tutorial online for this?

I like pie.

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824080
Share on other sites

Link to post
Share on other sites

1 minute ago, Windows Server 2003 said:

Is there a tutorial online for this?

Not that I know of, but definitely search around. If anything you'll likely find a solution better than the one I've suggested

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824094
Share on other sites

Link to post
Share on other sites

3 hours ago, burnttoastnice said:

Not that I know of, but definitely search around. If anything you'll likely find a solution better than the one I've suggested

Lol only reason I want a tutorial is because I have no idea about anything javascript

I like pie.

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824097
Share on other sites

Link to post
Share on other sites

1 minute ago, RollTime said:

Could Plex help you out? I've not tried it out, but it sounds like the kind of thing for this.

plex isnt really the best option for something like this.

 

why not just create a playlist on youtube and have him listen to that?

How do Reavers clean their spears?

|Specs in profile|

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824134
Share on other sites

Link to post
Share on other sites

Just now, Windows Server 2003 said:

Lol only reason I want a tutorial is because I have no idea about anything javascript

 

If you use a javascript library called jQuery, it'll only take a few lines of code. I'd write up some example code but I'm kinda busy (I should be doing uni work not browsing LTT). But that might be a stretch though if this is your first time using JavaScript.

 

As a starting point, I'd recommend just have a single PHP file pick a random song path and insert it into an audio tag, to test the overall concept. The php may should look something like this

 

<?php
	
	$folderPath = '';
	$songPath = '';

	// code here which reads the names of all the files in the songs folder, picks one random song and inserts it into $songPath variable

?>
<!doctype html>
<head>
  <title>Basic Radio</title>
</head>
<body>
  <audio controls src="<?php echo $songPath; ?>"></audio>
</body>

 

And then after that, all you need to do is tackle the JavaScript code.

Speedtests

WiFi - 7ms, 22Mb down, 10Mb up

Ethernet - 6ms, 47.5Mb down, 9.7Mb up

 

Rigs

Spoiler

 Type            Desktop

 OS              Windows 10 Pro

 CPU             i5-4430S

 RAM             8GB CORSAIR XMS3 (2x4gb)

 Cooler          LC Power LC-CC-97 65W

 Motherboard     ASUS H81M-PLUS

 GPU             GeForce GTX 1060

 Storage         120GB Sandisk SSD (boot), 750GB Seagate 2.5" (storage), 500GB Seagate 2.5" SSHD (cache)

 

Spoiler

Type            Server

OS              Ubuntu 14.04 LTS

CPU             Core 2 Duo E6320

RAM             2GB Non-ECC

Motherboard     ASUS P5VD2-MX SE

Storage         RAID 1: 250GB WD Blue and Seagate Barracuda

Uses            Webserver, NAS, Mediaserver, Database Server

 

Quotes of Fame

On 8/27/2015 at 10:09 AM, Drixen said:

Linus is light years ahead a lot of other YouTubers, he isn't just an average YouTuber.. he's legitimately, legit.

On 10/11/2015 at 11:36 AM, Geralt said:

When something is worth doing, it's worth overdoing.

On 6/22/2016 at 10:05 AM, trag1c said:

It's completely blown out of proportion. Also if you're the least bit worried about data gathering then you should go live in a cave a 1000Km from the nearest establishment simply because every device and every entity gathers information these days. In the current era privacy is just fallacy and nothing more.

 

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824145
Share on other sites

Link to post
Share on other sites

3 hours ago, Tsuki said:

plex isnt really the best option for something like this.

 

why not just create a playlist on youtube and have him listen to that?

Because my school blocks youtube, spotify, apple music, google play music, soundcloud. 

I like pie.

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824238
Share on other sites

Link to post
Share on other sites

If you already have a web server installed on it (like LAMP) than I would try AMPache http://ampache.org/.

 

You would of course need network attached audio files for it to play though. You would probably also have to use port 80 or 443 since you said your school blocks stuff (I bet 80 & 443 are wide open inbound; while most others will be blocked within the school). This might be difficult if you plan on doing this at home as most ISPs do not allow non-buisness class "home residents" to port-forward via these ports.

 

If you dont have alot music files than it might be easier to just play a youtube/spotify playlist on your windows machine, than use VLC to stream your "stero mix". port-forward, than connect to the audio stream playing on your computer remotely, but you would not be able to control what you listen to.

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10824578
Share on other sites

Link to post
Share on other sites

-= Locked =-

 

Discussion on ways to supersede, deter, break or otherwise avoid school lockouts are against the Community Standards.

Quote

Talking about piracy in general, broad details, is acceptable however the posting or discussing pirated/hacked/cracked or otherwise nefariously obtained content is not. This includes Windows content, games, hackintosh, etc. Also discussions regarding ways to avoid or block legitimately installed monitoring/tracking software or the like is also not allowed.

 

16 hours ago, Windows Server 2003 said:

Because my school blocks youtube, spotify, apple music, google play music, soundcloud. 

 

COMMUNITY STANDARDS   |   TECH NEWS POSTING GUIDELINES   |   FORUM STAFF

LTT Folding Users Tips, Tricks and FAQ   |   F@H & BOINC Badge Request   |   F@H Contribution    My Rig   |   Project Steamroller

I am a Moderator, but I am fallible. Discuss or debate with me as you will but please do not argue with me as that will get us nowhere.

 

Spoiler

Character is like a Tree and Reputation like its Shadow. The Shadow is what we think of it; The Tree is the Real thing.  ~ Abraham Lincoln

You have enemies? Good. That means you've stood up for something, sometime in your life.  ~ Winston Churchill

Reputation is a Lifetime to create but takes only seconds to destroy.

Docendo discimus - "to teach is to learn"

 

  

 CHRISTIAN MEMBER 

 
 
 
 
 
 

 

Link to comment
https://linustechtips.com/topic/873384-website-radio/#findComment-10826129
Share on other sites

Link to post
Share on other sites

Guest
This topic is now closed to further replies.

×