When a user of Internet Explorer 9 (or earlier versions of IE) visits my homepage, he/she hears my music in WMP (Windows Media Player). Other browser users (including IE 10 and later versions) see my music in a dropdown box. Why the different rendering of my home page in IE 9 (and earlier versions of IE)? The dropdown box utilizes a new html5 tag (new, as in it didn't exist in html 4.01 or earlier versions of html) called <audio>. The <audio> tag lets you play music in your web browser without a plug-in (like Adobe Flash) or a helper program (like WMP). Most web browsers today support html5. However, Windows XP (released to the general public in 2001) is still an extremely popular operating system, and the browser that came with it (IE 8) only supports html 4.01 and earlier versions of html. Windows 7 came packaged with IE 9 (which support html5), but it has a problem with the <select> tag (the dropdown box). So it's important (to me, at least) that my homepage plays music in WMP when it's visited by IE 9, or earlier versions of IE.
A play list for WMP can be stored as a list of URLs (usually a list of mp3 files on the Internet or on your PC) in a file that has the file type *.m3u My blog, Manipulating JSON with Node.js, describes how my web pages get automatically updated (actually, JavaScript in the pages do the update when the pages load) when I add songs to music.txt (the JSON file that contains all of the information needed for the updates), but how I have to run a server side script to update music.m3u Since I wrote that blog I've added a field to the JSON file for changing the document background when changing songs. ...and I just added another field; a field to prevent file updates.
Here's a section of music.txt:
"u213":{ "song": "music/duckinjuries.wav", "img": "image/purple.jpg", "name": "intro", "m3u": "true"},
"u212":{ "song": "music/WorkingClassHero.mp3", "img": "image/PlasticOnoBand.jpg", "name": "Working Class Hero", "m3u": "true"},
"u211":{ "song": "music/VoodooChild.mp3", "img": "image/ElectricLadyLand.jpg", "name": "Voodoo Chile (slight return)", "m3u": "true"},
"u210":{ "song": "music/RememberLove.mp3", "img": "image/UnfinishedMusic.jpg", "name": "Remember Love", "m3u": "true"},
"u209":{ "song": "music/MonsterMash.mp3", "img": "image/ElviraPresentsHauntedHits.jpg", "name": "Monster Mash", "m3u": "" },
"u208":{ "song": "music/Lilies.mp3", "img": "image/TheHauntedMan.jpg", "name": "Lilies", "m3u": "true"},
Notice the new field (you'll notice it if you've seen my last three blogs), m3u. Most occurrences of m3u have an associated field, "true". If you look at my script that creates music.m3u, you'll see that I now test for this field being "true" or "" (false):
var fs = require('fs');
var file = 'music.txt';
var os = require('os');
fs.readFile(file, 'utf8', function (err, data)
{
if (err)
{
console.log('Error: ' + err);
return;
}
data = JSON.parse(data);
for (obj in data)
{
console.log(data[obj].song);
// 11/03/2014 DMK, just added a flag to music.txt too check if we should append this record or not
if (data[obj].m3u)
{
fs.appendFileSync('music.m3u',data[obj].song + os.EOL);
}
}
});
Look back at my snippet from music.txt; Monster Mash is false. I added the song Monster Mash to my list on Halloween, and left it there so site visitors could enjoy the album artwork. However, I added a boolean (true or false) field to music.txt so I could exclude it from music.m3u (I don't change the document background for IE 9 and earlier versions of IE). A while back my wife asked me to add the theme songs from the TV shows "Monk" and "Perry Mason" to her homepage; I added them to my homepage, too. I really don' want to play those TV show theme songs on my homepage, unless visitors can see the album artwork; Monk and Perry Mason now have false flags, too.
Looking back at the modifications to music.txt and the script for creating music.m3u, you can see they're pretty trivial. Yet, these simple changes show how to use boolean logic when dealing with JSON and Node.js Going through all of the logic that went into the changes is also instructive from a programming tutorial standpoint, and gives me a reason to include this web page in my list of blogs and not just in my list of programs.