Adabox004 streaming player with remote

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Adabox004 streaming player with remote

Post by jcalvin »

Was playing around with the streaming player and added the IR remote code to it. Then I needed something for the remote to do other than change the volume. So I added some code to read a list of internet streaming "stations" and allow CH+/- to switch between them. Code attached.

stations.txt file looks like (tab separated)

ice1.somafm.com /u80s-128-mp3 80
centova.orsradio.com / 8192
centova.orsradio.com / 8006

etc.

Since the SD card is there, it remembers the last volume setting and which station was selected.

18 Jul: Added check to see if connection died due to long pause or other reason. Restart stream if so.
Attachments
WiFIPlayerv4.txt
(14.63 KiB) Downloaded 168 times
Last edited by jcalvin on Tue Jul 18, 2017 11:32 am, edited 3 times in total.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adabox004 streaming player with remote

Post by adafruit_support_mike »

Interesting.. thanks for posting it!

ianm1
 
Posts: 1
Joined: Fri Mar 29, 2013 1:44 pm

Re: Adabox004 streaming player with remote

Post by ianm1 »

This is great. Where did you get the port list of stations on OrsRadio? Can't seem to find it on their site.

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: Adabox004 streaming player with remote

Post by jcalvin »

I didn't find a list either. But from the main page at http://www.orsradio.com/ click on one of the stations. A new page comes up that also does not show the port number. But if you click on the "listen in your favourite player" icons (I used the windows one) a small file will be downloaded that contains the URL and port number for that station.

Hope this helps.

User avatar
jwilfong
 
Posts: 4
Joined: Sat Sep 14, 2013 6:19 pm

Re: Adabox004 streaming player with remote

Post by jwilfong »

Awesome! I was working on the same idea and saw you already did it!

Need to make a small change. The final station added cannot be accessed by pressing it's number. It is accessible using channel up and down but not by number. In the final if statement of your code change < to <=:

Code: Select all

if (remoteNumber <= nextStationIDX) {
You also have the buttons of the remote defined at the top of the code but reference their values in the loop. Everything works but for readability change the test of lastRemoteValue to ....

Code: Select all

if ( (lastRemoteVal == kRemoteVolumeUp) || (lastRemoteVal == kRemoteVolumeDown)) {
         code = lastRemoteVal;
It's also noteworthy that the last station in stations.txt must end with a CR/LF. Without it the code fails. I hacked together a test for the end of file to prevent this. It seems that this SD library can't be tested for -1 to indicate an end of file. Looks like you can test for ascii 207. Works for me, your mileage can vary. Last station in stations.txt can have CR/LF or it can be omitted and the code will run. I added the following if statement to the readToken procedure:

Code: Select all

  char eofChar = 207 + '0';   // convert ascii 207 to char

  while (true) {
    theChar = stFile.read();
	
	if (theChar == eofChar) {    // check if end of file reached
 		token[idx] = 0;  
		return token;
	}

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: Adabox004 streaming player with remote

Post by jcalvin »

Thanks for the bug catches - fixed both as well as the case where I didn't use the defined constants.

User avatar
dconley
 
Posts: 16
Joined: Wed Mar 22, 2017 8:52 pm

Re: Adabox004 streaming player with remote

Post by dconley »

One thing I noticed, which isn't a big deal but could be a learning opportunity, is that the code could be shortened a bit with modulo math.

Code: Select all

currentStation = currentStation + 1;
if (currentStation >= nextStationIDX) {
    currentStation = 0;
}
You can change this to

Code: Select all

currentStation = (currentStation + 1) % nextStationIDX;
This uses the remainder of dividing currentStation + 1 by nextStationIDX, which will be currentStation + 1 as long as it's less than nextStationIDX (1/4 is 0 with a remainder of 1), but 0 once it reaches the max! And if you somehow managed to jump 2 above the max (maybe pounding on the channel up button?) it would still translate into the second station (number 1). Think of it like a clock, with the hand starting over at 12.

Again: your code works fine, and I'm not trying to nitpick! But modulo is neat and I like using it.

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: Adabox004 streaming player with remote

Post by jcalvin »

Thanks for the suggestion of using modulo math. It's fairly concise and probably generates a bit less code.

However, in this case (and most) I usually use the most obvious coding constructs to make it clear what I'm attempting to do (and like everything else it life, often fall short on this endeavor ;) . If I need to optimize for space or speed, I'll do that as necessary later, often leaving the original code in place, but commented out to help me remember what I was originally trying to do.

You'll also notice I don't even use the ++ and -- constructs. This partially due to my background, and partially due to my guess that some folks using Adafruit products may have different, or very limited, coding backgrounds. So I try to keep it somewhat obvious.

That said, it's a good construct for folks to know about and use.
Thanks for the comment!

User avatar
perrycannon
 
Posts: 3
Joined: Sat Dec 26, 2015 9:24 am

Re: Adabox004 streaming player with remote

Post by perrycannon »

Can you post the stations.txt file? I have been searching for internet radio mp3 streams. Sites hide there path and host name.

Is it possible to use pls and m3u streams?

User avatar
jcalvin
 
Posts: 52
Joined: Mon Jan 04, 2016 3:37 pm

Re: Adabox004 streaming player with remote

Post by jcalvin »

I've attached my copy of stations.txt. Streams seem to come and go a bit - my original list had half dozen from a site that now seems dead.

From my brief reading, m3u and pls seem to be playlist files rather than a stream. The contents of one of those files could be examined to get a stream address.

If you do a search for "mp3 stream lists" you'll find sources of streams. Sometimes it requires downloading a file and getting the actual stream address from within the file. Sometimes a little trial and error...
Attachments
stations.txt
A few stations to try with WiFiPlayer
(260 Bytes) Downloaded 162 times

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”