Linux HTML5 Audio

 

If you read my last two posts, then you know that I'm running Pussy Linux on Caprica. In fact, I'm writing this blog on Caprica right now, using Pussy Linux. One of the first things I did with Pusy Linux was download a more up to date browser. The packaged browser was SeaMonkey 2.4. I downloaded SeaMonkey 2.14.1 and took a look at my own website. On Windows systems I would hear music playing the moment my home page opened up. I setup html5 audio to play on IE 9 and above, Windows Media Player to run on IE 8 and lower, and Realplayer on all other browsers. I also included html5 audio on Android systems when I found out that it ran on my Android tablet. So I wasn't shocked to not hear music on Pussy Linux, since it would be trying to run Realplayer; Realplayer is a Windows only application.

I like Pussy Linux so much that I plan on using it as my main OS on Caprica, so I decided to make my music jukebox play on Linux. Obviously I have to test for Linux, but what should I do next (did next; I already did it)? There are two possibilities; (1) Run a media player, like Alsaplayer, or (2) dynamically change the endings of my sound files to one that is playable by the html5 <audio> tag. I decided go with method (2), but what sound type to use? I looked up the playable sound types in html5 and found out that wav files will play in every browser except Internet Explorer! I don't have to worry abut IE on Linux, so all I have to do is test for Linux and dynamically change the ending of my sound files from mp3 to wav (..and of course, create a wav file duplicate of each mp3 file I have).


function changeSong()
         {
            var browser;
            var songSrc;
            browser = navigator.userAgent.toLowerCase();            
            var SongList = document.getElementById("SongList");
            var jukebox  = document.getElementById("jukebox");
            if ((browser.indexOf('linux') != -1))
            {
               songSrc = SongList.value;
               songSrc = songSrc.substring(0, songSrc.length - 3) + "wav";               
               jukebox.src = songSrc; 
            }
            else
            {
               jukebox.src = SongList.value;            
            }
         }  

Feel free to look at the souce code of http://community-info.org/index.html so the above code will make more sense. This works so well that I'll probably discard Realplayer and move strictly to html5 audio. My reason for using Realplyer was that Firefox doesn't run Windows Media Player anymore. Firefox doesn't play html5 audio either, if your sound files are mp3s. By using Realplayer I didn't have to create a second batch of sound files. ...but now I have to create duplicate sound files if I like it or not, and I can use these sound files in any browser on any platform, so I really should simplify my code by discarding Realplayer. Like I said, feel free to look at my source code; I'll probably change it in the near future.

 

Return To My Blog Page       Return To My Programming Page