Living By The Beat

The best of radio, in the modern world

About The Radio

Java Script (User Side) Program:

This is the program that allows the radio to switch to the larger view on the “radio” page. The program begins by storing the url of the user’s current page. Then depending on whether on not the user’s connection is secure it tests to see if they are on the radio page. If they are then it switches the ID of the normal radio element on the sidebar and changes it to the “connected on alternate screen” image. It then changes the larger display element to have the ID “music” so that the rest of the JavaScript updates that page element instead.
The next section of the program begins by declaring a variable to refer to the display element of the page and other global variables. Then it calls the function “getDataOnServer” which gets songs to be played on the radio from the server.
This is the “getDataOnServer” function. This function creates an array and then fetches a file from the server. This file is made up of objects that represent songs to be played on the radio. These objects have 5 attributes: the songs name, the YouTube video code, the length (in milliseconds) of the song, the song’s playlist, and the time the song should play (in seconds). This function loops through these objects and adds them to a result array starting with the song that should theoretically be playing now (calculated using the user’s time in seconds and the time the song should play in seconds). Then the function “loopNew” is called and passed the array of songs that the user should play.
This is the “getCurrentTime” function used previously in the “getDataOnServer” function. It uses a Java Script date object then calculates and returns the current time of day in seconds.
This function, title “loopNew” is what preforms the bulk of the operations for the radio. This takes in an array of the song objects and plays them on the page element with the ID “music”. The first thing that this function does is check if it is running for the first time. If this is true then it creates a buffer for the current song by calculating the difference between the users current time and the time that the song should play. Then the function creates a YouTube embed url with the song’s internal youtube code and sets the start time to the buffer. Next the time that the program should wait before switching the song is calculated by getting the song’s length in milliseconds and subtracting the buffer (converted to milliseconds). Then the “music” page element’s url is updated to the one that was just created. After this is done the function “nextPlaylist” is called. This function checks if the current song will run into the next playlist. If it will, then the function returns the time of day (in seconds) that the next playlist will start. If the song won’t run into a new playlist, it returns -1. Based on the output of this function the “loopNew” function decides what should be done with the song object. If the song won’t run into the next playlist then it waits until the song is finished and then calls the same “loopNew” function again and passes it the same array that it was originally passed in “getDataOnServer”. If the song will run into the next playlist then the function calculates how long from the current time does the next playlist occur. It then waits that long before calling the “getDataOnServer” function which will retrieve a new song list of songs from the new playlist off of the server.
This is the “goPastPlaylist” function mentioned before. It adds the songs length to the current time and then checks it against the playlist start times, returning the one that it will go past or -1.
Pages:Previous | Next

Radio:

Select broadcast:

Listening to: N/A

By: N/A
Read Lyrics Here

Recent Posts

Recent Comments

Archives